Python: Error in the loop

See, I started learning Python today and I am stuck in a situation. I was solving a very simple question and I completed it but there is a problem. First of all, let me tell the question and the constraints. Here is the question: Given an integer,n,

Counting of nucleotides and sequences

I have a problem counting nucleotides and sequences at the same time in Python. This is the fasta file and I need to count nucleotides and sequences. Please see below how it must be the asnwer: >chr12_9180206_+:chr12_118582391_+:a1;2 total_counts: 11

How do I make a hidden file on Windows?

On windows you can right-click a file, click on properties and select hidden. How can I do this to a file in python?If you don't want/don't have access to win32 modules you can still call attrib: import subprocess subprocess.check_call(["attrib"

Python as part of the robot - Se2Lib has no 'run'

in my Robot framework tests I need some custom python keywords (e.g. to hold CTRL key) And everything worked before I started refactoring my "big" custom class (but I did not really change anything in this part around hold CTRL). Now I am gettin

How do I use Boto3 to start an EC2 instance with an IAM role?

I can not figure out how to launch an EC2 instance in Boto3 with a specified IAM role. Here is some sampe code of how I have been able to successfully create an instance so far: import boto3 ec2 = boto3.resource('ec2', region_name='us-west-2') ec2.cr

Combine the lines of the data frame on the conditions

I have a pandas-dataframe that looks like: INPUT - here the example runnable code to create the INPUT: #Create Dataframe with example data df_example = pd.DataFrame(columns=["START_D","ID_1", "ID_2", "STOP_D"]) df_e

Python BeautifulSoup scrape Yahoo Finance value

I am attempting to scrape the 'Full Time Employees' value of 110,000 from the Yahoo finance website. The URL is: http://finance.yahoo.com/quote/AAPL/profile?p=AAPL I have tried using Beautiful soup, but I can't find the value on the page. When I look

return the string with the first Regex part

I want to get the first match of a regex. In this case, I got a list: text = 'aa33bbb44' re.findall('\d+',text) ['33', '44'] I could extract the first element of the list: text = 'aa33bbb44' re.findall('\d+',text)[0] '33' But that only works if there

django Get a foreign key model in view and display in html

So I have two models: class UserMeasurements(models.Model): user = models.CharField(max_length=20) time = models.DateTimeField(blank=True, null=True) set = models.ForeignKey(PhotoSets, models.DO_NOTHING) class Meta: managed = False db_table = 'user_m

How to replace a string in a list randomly

If I have something like this: L = ['-','-','-','-','-','-','-'] And let's say that I want to replace certain number of those strings. How do I randomly select a position within the list to replace it for something else? For example: L = ['-','*','-'

Python: Theme message box Tkinter / ttk

I started making a GUI with Tkinter and I added the module tkMessageBox as well. But recently I discovered that importing the module ttk gives more 'up-to-date' results: buttons and texts boxes appear with the actual style of the current OS. This is:

Prevent change of field if related objects exist?

I have two models in my Django application: class Survey(models.Model): survey_type = models.CharField(max_length=1, choices=SURVEY_TYPES) class Response(models.Model): survey = models.ForeignKey(Survey) response = models.TextField() When the organiz

How to align two tables after sorting one?

I have two list which their values match with each others positions. So Jon's score would be 123 and Bede's would be 11 etc. name = ["Jon", "Bede", "Joe"] score = [123, 11, 43] How is it possible to order the the list so that

Loop on a list with strings of different lengths

Lets say I have a list like this. a = [1, 23, 456, 6789] And I want to change the position of the elements in each position of the list. The output would be, every number is moved up one position until the end of the string, and it moves to the front

Manipulating large amounts of image data in Python

I have a large number of images of different categories, e.g. "Cat", "Dog", "Bird". The images have some hierarchical structure, like a dict. So for example the key is the animal name and the value is a list of animal images,

Pygame Collision detects with object and rect

Yep, I'm asking another question about this program :D Anyway, I currently a program that creates two lines on the screen with a gap in between them that can scroll. From here, I obviously need to see if the two objects are colliding. Since I only ha

How I can miniature an image with Python

I want to thumbnail an image with Python (resize it to small size). How I can do this? Do you know any library to do this work?I write a simple script to thubmnail add picture of in directory. maybe this can help.

Python RLock IO-Bound?

I have a set of CPU-bound processes that take any number of cores to 100% utilization as long as their only synchronization is getting jobs out of a Queue. As soon as I add an RLock to avoid worst case scenarios when updating a directory in the file

PIL ImageTk equivalent in Python 3.x

I'm developing an application with Tkinter that uses a database of png image files for icons. In order to use said images in the application, I open them using PIL's Image.open, run it through the ImageTk.PhotoImage function, then pass it to the widg

PyGame MP3 will not play

I'm using the code: import pygame, sys, datetime from pygame.locals import * pygame.init() screen = pygame.display.set_mode((640, 480)) screen.fill((0, 0, 0, 255)) pygame.display.set_caption("TESTIFICATE") if datetime.date.today().month == 12 an

Python-based password Tracker (or dictionary)

Where we work we need to remember about 10 long passwords which need to change every so often. I would like to create a utility which can potentially save these passwords in an encrypted file so that we can keep track of them. I can think of some sor

testing python applications that use mysql

I want to write some unittests for an application that uses MySQL. However, I do not want to connect to a real mysql database, but rather to a temporary one that doesn't require any SQL server at all. Any library (I could not find anything on google)

How to hide the console window in python?

I am writing an IRC bot in Python. I wish to make stand-alone binaries for Linux and Windows of it. And mainly I wish that when the bot initiates, the console window should hide and the user should not be able to see the window. What can I do for tha