python

reading and extracting data from file using python

hello , i am new to python , and I want to extract the data from this format FBpp0143497 5 151 5 157 PF00339.22 Arrestin_N Domain 1 135 149 83.4 1.1e-23 1 CL0135 FBpp0143497 183 323 183 324 PF02752.15 Arrestin_C Domain 1 137 138 58.5 6e-16 1 CL...

Convert GNU find command to Python function

I want to convert this GNU command into a python function: find folder/ 2>/dev/null > file.txt The find will list all files and folders from the directory recursively and write them to a file. What I have now in Python is: import os project="/folder/path" i=0 for (project, dirs, files) in os.walk(project): print project print ...

Check to see if system volume is muted?

Hello everyone. I am working on a project that plays audio for part of the program. I would like to be able to display a message if the user's system volume is muted. I am using Python on Windows. ...

how to log or store the request and response between host and my application in python

we have an application through which we connect to remote host on port 23 and we have to do some repetative work.. what i am thinking is while runnig that application manually can i log or store the request that apllication sending to remote host and what resposes application receving to that request i have to run my application and at...

Twisted Matrix and telnet server implementation

I have a project which is essentially a game server where users connect and send text commands via telnet. The code is in C and really old and unmodular and has several bugs and missing features. The main function alone is half the code. I came to the conclusion that rewriting it in Python, with Twisted, could actually result in faster...

python: importing modules with incorrect import statements => unexhaustive info from resulting ImportError

Hi there, I have a funny problem I'd like to ask you guys ('n gals) about. I'm importing some module A that is importing some non-existent module B. Of course this will result in an ImportError. This is what A.py looks like import B Now let's import A >>> import A Traceback (most recent call last): File "<stdin>", line 1, in <modu...

How do I get the application title of a Google AppEngine app from within that app

Under the application settings page in the Administration console, it is possible to specify a name for the application, AFAIK this is used in the login page when using the users API to login. I would like to be able to use this information within an application, currently, the title is also specified in a separate configuration file, b...

How can i read bzr repository from python script?

like getting information about changesets/comments etc. ...

Common elements comparison between 2 lists.

def common_elements(list1, list2): """ Return a list containing the elements which are in both list1 and list2 >>> common_elements([1,2,3,4,5,6], [3,5,7,9]) [3, 5] >>> common_elements(['this','this','n','that'],['this','not','that','that']) ['this', 'that'] """ for element in list1: if element in ...

removing elements incrementally from a list

Dear all, I've a list of float numbers and I would like to delete incrementally a set of elements in a given range of indexes, sth. like: for j in range(beginIndex, endIndex+1): print ("remove [%d] => val: %g" % (j, myList[j])) del myList[j] However, since I'm iterating over the same list, the indexes (range) are not valid any ...

Finding out event that called a CGI script

What I want is to be able to make my CGI script do different things depending on what action initiated the calling of the script. For example, if one button is pressed, a database is cleared. If another button is pressed, a form is submitted and that data is added to the database. Should I be doing something like adding the name of the...

How to save to two tables using one SQLAlchemy model

I have an SQLAlchemy ORM class, linked to MySQL, which works great at saving the data I need down to the underlying table. However, I would like to also save the identical data to a second archive table. Here's some psudocode to try and explain what I mean my_data = Data() #An ORM Class my_data.name = "foo" #This saves just to the 'da...

Best resources for learning PyGame?

Hey all, Just curious if anyone knows of good sites for learning and understanding PyGame. I've programmed a bunch in Python, so I'm well-equipped with that. Just curious if anyone knows a good site or more for learning PyGame. Thanks for any help! ...

Python3 function annotations for type hinting versus Boo

I've started on a medium-sized project in python, and I decided to use python 3 because I'm not using any large external libraries and py3k has some nice new syntactic sugar and more importantly function annotations. However, it seems like none of WingIDE, Pydev, or pycharm actually have any support for type hinting using function annota...

logical operators evaluation in return statemnet in python

hi, how does this execute: def f(x): return x>0 and (x%2)+f(x/2) or 0 x is an array ,for instanse,[1, 1, 1, 3] thank u ...

Python - Removing duplicates from a string

def remove_duplicates(strng): """ Returns a string which is the same as the argument except only the first occurrence of each letter is present. Upper and lower case letters are treated as different. Only duplicate letters are removed, other characters such as spaces or numbers are not changed. >>> remove_dupl...

Python Textwrap - forcing 'hard' breaks

I am trying to use textwrap to format an import file that is quite particular in how it is formatted. Basically, it is as follows (line length shortened for simplicity): abcdef <- Ok line abcdef ghijk <- Note leading space to indicate wrapped line lm Now, I have got code to work as follows: wrapper = TextWrapper(width=80, subseque...

In Python, how to find all the files under a directory, including the files in subdirectories ?

Is there any built in functions to find all the files under a particular directory including files under subdirectories ? I have tried this code, but not working...may be the logic itself is wrong... def fun(mydir): lis=glob.glob(mydir) length=len(lis) l,i=0,0 if len(lis): while(l+i<length): if os.pat...

Best way to change Satchmo checkout page fields?

For a Satchmo project we have to change the fields a customer has to fill out during checkout. Specifically, we have to: Add a 'middle name' field Replace the bill and delivery addressee with separate first, middle and last name fields Replace the two address lines with street, number and number extension These fields are expected by...

How to unescape special characters from BeautifulSoup output?

Hi, I am facing issues with the special characters like and which represent the degree Fahrenheit sign and the registered sign, when i print the string the contains the special characters, it gives output like this: Preheat oven to 350&deg; F Welcome to Lorem Ipsum Inc&reg; Is there a way I can output the exact characters and n...