python

irc bot cant join channel

import socket irc = 'irc.hack3r.com' port = 6667 channel = '#chat' sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sck.connect((irc, port)) sck.send('NICK supaBOT\r\n') sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n') sck.send('JOIN #chat' + '\r\n') data = '' while True: data = sck.recv(4096) if data.find('...

How do quickly search through a .csv file in Python

I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry. Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but that took ages so I'm current...

Python Thread/Queue issue..

I'm creating a threaded python script that has a collection of files that is put into a queue and then an unknown amount of threads (default is 3) to start downloading. When each of the threads complete it updates the stdout with the queue status and a percentage. All the files are being downloaded but the status information is wrong o...

Google Books API - How do I separate Book from Book Edition?

Hi, I'm using Google Book Search API to add missings bits and pieces to my database. Problem is that The API gives me back a list of book editions, and not reference to the original book itself. The data I'm trying to get is this: Original title: The Hobbit Original year of publication: 1937 Can anyone help? Just in case...

How to I extract floats from a file in Python?

So, I have a file that looks like this: # 3e98.mtz MR_AUTO with model 200la_.pdb SPACegroup HALL P 2yb #P 1 21 1 SOLU SET RFZ=3.0 TFZ=4.7 PAK=0 LLG=30 SOLU 6DIM ENSE 200la_ EULER 321.997 124.066 234.744 FRAC -0.14681 0.50245 -0.05722 SOLU SET RFZ=3.3 TFZ=4.2 PAK=0 LLG=30 SOLU 6DIM ENSE 200la_ EULER 329.492 34.325 209.775 FRAC 0.70297 0....

python and process

Hi, What is the best way in python find the process name and owner? Now i use WMI, but this version is too slow. ...

Combining words in Python (permutations?)

Suppose I have 4 words, as a string. How do I join them all like this? s = orange apple grapes pear The result would be a String: "orangeapple/orangegrapes/orangepear/applegrapes/applepear/grapespear/orangeapplegrapes/orangeapplepear/applegrapespear" I am thinking: list_words = s.split(' ') for l in list_words: And then use enum...

Positional Rankings and Dealing with Ties in Python

(I apologize that previous versions of this question displayed the wrong function that I need to fix, this has been remedied and I hope the question makes a little more sense now.) I have a list of objects with scores, and I'm attempting to assign rank to them based on those scores. Below is basically how I output my data. sorted_score...

Building a wiki application?

Hi folks, I'm building this app in Python with Django. I would like to give parts of the site wiki like functionality, but I don't know how to go on about reliability and security. Make sure that good content is not ruined Check for quality Prevent spam from invading the site The items requiring wiki like functionality are just a f...

Problem with asyn icmp ping

I'm writing service in python that async ping domains. So it must be able to ping many ip's at the same time. I wrote it on epoll ioloop, but have problem with packets loss. When there are many simultaneous ICMP requests much part of replies on them didn't reach my servise. What may cause this situation and how i can make my service ping...

Django: When using register.inclusion_tag() where/what order is the template searched for?

When using the register.inclusion_tag() shortcut on a Custom Template Tag, assuming you define the template as 'some_fragment.html', in what directories/order does Django try to find that template? Assume as many 'defaults' as is reasonable. The Custom Template Tag portion of the documentation doesn't list anything specific, except t...

why python associative map member variable is shared between objects

For class A, why is aMap member variable being shared between object and object b? >>> class A: ... aMap = {} >>> a = A() >>> a.aMap["hello"] = 1 >>> b = A() >>> b.aMap["world"] = 2 >>> c = [] >>> c.append(a) >>> c.append(b) >>> for i in c: ... for j in i.aMap.items(): ... print j ('world', 2) ('hello', 1) ('worl...

How do I add five numbers from user input in Python?

As a practice exercise, I am trying to get five numbers from a user and return the sum of all five number using a while loop. I managed to gather the five numbers, but the sum is not provided by my code (I get a number, but it is always double the last number). I believe the issue is with my use of +=. x = 0 while x < 5: x += 1...

RPC lib for Python

What RPC framework/lib for python could you recommend me? The architecture is client-server, server should stand high load, and connection tunneled over ssl. I've googled such things as pyro, twisted.spread, rpyc. ...

Django FormSets as Fields of another Form

I have a Django model that looks like this: DEFAULT_PROFILE_INFO = [ {"name":"About Me", "body":"Super programmer", "public":True}, {"name":"Research", "body":"Various topics", "public":False} ] class Profile(models.Model): user = models.OneToOneField(User, unique=True) info = JSONField(blank=True, default=DEFAULT_PROFI...

retrieving the keys of all variables on an object

If I had: class A(object): varA = 1 inst = A() Then how would I retrieve the keys of all variables on inst? I'd want something like ["varA"] So far, I've gotten this: vars(inst.__class__).keys() #returns ['__dict__', '__weakref__', '__module__', 'varA', '__doc__'] I'm fine with that, I'd just ignore the double-under vars. My ...

If you are really good at Python and Regex, please help fix function.

def boldword(text, needle): return mark_safe(re.compile(r"\b(%s)\b" % "|".join(map(re.escape, needle.split(' '))), re.I).sub(r'<strong>\1</strong>', text)) This is currently my function to bold a string text given a needle. (Like Google...they bold the text for you when you do a search). When the needle is "the show", it will not...

Installing Mercurial 1.4.3 - Python Requirement?

Is it ok if I install Python 2.6.4 instead of the 2.4 requirement listed on the Mercurial website? I'm fairly new to Mercurial and Python. My general impression of Python is that newer versions break compatibility with older versions. If Python is currently at 2.6.4 and Mercurial 1.4.3 lists Python 2.4 as a requirement, maybe they are ...

Basic Django - Custom Managers

I'm going through the Django book and I'm currently on chapter 10. I'm having a problem understanding the third line in this fragment of code: class DahlBookManager(models.Manager): def get_query_set(self): return super(DahlBookManager, self).get_query_set().filter(author='Roald Dahl') I understand that this custom manager...

Problem in calculating checksum : casting int to signed int32

Hi, I need to convert the following c code (to calculate checksum for a file) to python. I had written, the corresponding code in python but the result didn't match the c version. The problem was that python autmatically promotes int to long whenever overflow occurs and this results in wrong checksums. Any idea how to overcome this pro...