python

How to obtain ports that a process in listening on?

How do I get the ports that a process is listening on using python? The pid of the process is known. ...

Is it possible to post binaries to usenet with Python?

Hey All, I'm trying to use the nntplib that comes with python to make some posts to usenet. However I can't figure out how to post binary files using the .post method. I can post plain text files just fine, but not binary files. any ideas? -- EDIT-- So thanks to Adrian's comment below I've managed to make one step towards my goal. I...

Dealing with wacky encodings in Python

I have a Python script that pulls in data from many sources (databases, files, etc.). Supposedly, all the strings are unicode, but what I end up getting is any variation on the following theme (as returned by repr()): u'D\\xc3\\xa9cor' u'D\xc3\xa9cor' 'D\\xc3\\xa9cor' 'D\xc3\xa9cor' Is there a reliable way to take any four of the abov...

Read -> change -> save. Thread safe.

This code should automatically connect players when they enter a game. But the problem is when two users try to connect at the same time - in this case 2nd user can easily overwrite changes made by 1st user ('room_1' variable). How could I make it thread safe? def join(userId): users = memcache.get('room_1') users.append(user...

Any high-level languages that can use c libraries?

I know this question could be in vain, but it's just out of curiosity, and I'm still much a newb^^ Anyways I've been loving python for some time while learning it. My problem is obviously speed issues. I'd like to get into indie game creation, and for the short future, 2d and pygame will work. But I'd eventually like to branch into the ...

Python Threading

I'm trying to make a simple program that continually displays and updates a label that displays the CPU usage, while having other unrelated things going on. I've done enough research to know that threading is likely going to be involved. However, I'm having trouble applying what I've seen in simple examples of threading to what I'm try...

How is the 'is' keyword implemented in Python?

... the is keyword that can be used for equality in strings. >>> s = 'str' >>> s is 'str' True >>> s is 'st' False I tried both __is__() and __eq__() but they didn't work. >>> class MyString: ... def __init__(self): ... self.s = 'string' ... def __is__(self, s): ... return self.s == s ... >>> >>> >>> m = MyString() >>> m ...

Parallelism in Python

What are the options for achieving parallelism in Python? I want to perform a bunch of CPU bound calculations over some very large rasters, and would like to parallelise them. Coming from a C background, I am familiar with three approaches to parallelism: Message passing processes, possibly distributed across a cluster, e.g. MPI. Exp...

String comparison in Python: is vs. ==

I noticed a Python script I was writing was acting squirrelly, and traced it to an infinite loop, where the loop condition was "while line is not ''". Running through it in the debugger, it turned out that line was in fact ''. When I changed it to != rather than 'is not', it worked fine. I did some searching, and found this question, t...

which file stored os.environ,and store where , disk c: or disk d:

my code is : os.environ['ss']='ssss' print os.environ and it show : {'TMP': 'C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp', 'COMPUTERNAME': 'PC-200908062210', 'USERDOMAIN': 'PC-200908062210', 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', 'PROCESSOR_IDENTIFIER': 'x86 Family 6 Model 15 Stepping 2, GenuineIntel', 'PROGRAMFILES': 'C...

python return class

Hi I new to python and I read from someone else of the example code below: class A: def current(self): data = Data(a=a,b=b,c=c) return data class B(A): #something here #print data a b c How do I print out the data a, b, and c? ...

Better ways to print out column names when using cx_Oracle

Found an example using cx_Oracle, this example shows all the information of Cursor.description. import cx_Oracle from pprint import pprint connection = cx_Oracle.Connection("%s/%s@%s" % (dbuser, dbpasswd, oracle_sid)) cursor = cx_Oracle.Cursor(connection) sql = "SELECT * FROM your_table" cursor.execute(sql) data = cursor.fetchall() p...

How to read a single character at a time from a file?

I want to read a single character at a time from a file in python. Can anyone tell me how can I do this? ...

How to prevent BeautifulSoup from stripping lines

I'm trying to translate an online html page into text. I have a problem with this structure: <div align="justify"><b>Available in <a href="http://www.example.com.be/book.php?number=1"&gt; French</a> and <a href="http://www.example.com.be/book.php?number=5"&gt; English</a>. </div> Here is its representation as a python string: '<d...

Django localeURL when WSGIScriptAlias is /PREFIX

Good morning everyone, Introduction I Got a question about localeURL usage. Everything works great for me with url like this : http://www.mysite.com/ If I type http://www.mysite.com/ in adress bar, it turns correctly in http://www.mysite.com/en/ for example. If I use the view change_locale, it's also all right (ie change www.mysite...

manyToManyField question

Hay guys, I'm writing a simple app which logs recipes. I'm working out my models and have stumbled across a problem My Dish models needs to have many Ingredients. This is no problem because i would do something like this ingredients = models.ManyToManyfield(Ingredient) No problems, my dish now can have many ingrendients. However, t...

what is useful of os.environ in google-app-engine , why google use os.environ so many times.

why google use so many os.environ .. thanks ...

OverflowError: math range error

>>> import math >>> math.pow(2, 3000) Traceback (most recent call last): File "<stdin>", line 1, in <module> OverflowError: math range error How can I fix it? thanx. ...

cherrypy when to know that the server has started

I am trying to write some unit tests for a small web service written with Cherrypy and I am wondering what's the best way to figure out that the server has started, so i don't get connection refused if I try to connect too early to the service ? ...

How to show why "try" failed in python

is there anyway to show why a "try" failed, and skipped to "except", without writing out all the possible errors by hand, and without ending the program? example: try: 1/0 except: someway to show "Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> 1/0 ZeroDivisionError: integer d...