python

How to efficiently merge multiple list of different length into a tree dictonary in python

given [ ('object-top-1','object-lvl1-1','object-lvl2-1'), ('object-top-2','object-lvl1-1','object-lvl2-2','object-lvl3-1') ('object-top-1','object-lvl1-1','object-lvl2-3'), ('object-top-2','object-lvl1-2','object-lvl2-4','object-lvl3-2','object-lvl4-1'), ] and so on .. where all the tuples are of arbitrary length Any way to ...

ISDN dial up connection with python

Hi all, I have a requirement to create a Python application that accepts dial up connections over ISDN from client software and relays messages from this connection to a website application running on a LAMP webserver. Do we have some modules or support for this kind of implementation in python? Please suggest. Thanks in advance. ...

question about python names using a default parameter value

I was reading this today: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#default-parameter-values and I can't seem to understand what's happening under the hood. def bad_append(new_item, a_list=[]): a_list.append(new_item) return a_list The problem here is that the default value of a_list, an empty ...

What's the best layout for a python command line application?

What is the right way (or I'll settle for a good way) to lay out a command line python application of moderate complexity? I've created a python project skeleton using paster, which gave me a few files to start with: myproj/__init__.py MyProj.egg-info/ dependency_links.txt entry_points.txt PKG-INFO SOURCES.txt top_level.txt zip-s...

IP address conversion using Python.

I want to convert an ip address read from a file in the decimal format (192.168.65.72) to one in binary format {110000001010100001000001010001000}.I am reading the ip address in the decimal format from a file.Find the code snippet below. /*contains 192.168.65.72*/ filter = open("filter.txt", "r") for line in filter: bytePattern = "...

Copying a file with access locks, forcefully with python

Hi, I'm trying to copy an excel sheet with python, but I keep getting "access denied" error message. The file is closed and is not shared. It has macros though. Is their anyway I can copy the file forcefully with python? thanks. ...

How to depends of a system command with python/distutils?

Hi, I'm looking for the most elegant way to notify users of my library that they need a specific unix command to ensure that it will works... When is the bet time for my lib to raise an error: Installation ? When my app call the command ? At the import of my lib ? both? And also how should you detect that the command is missing (if ...

I have trouble installing the django-socialregistration app!

Hi, I'm a Django amateur, and have problems getting django-registration to work. I followed the installation instructions on their website, but for someone like me these instructions are not 100% clear as to what I should be doing. Here is what I've done: I installed the oauth2 and python-openid packages using pip. I then copied the f...

simplest way to return a new list by remove index/value from another list? (order required)

All, o1 = ["a","b","c","d","e","f","g","h"] index = [3,4] value = ["c","d"] [x for x in o1 if x not in value] [x for x in o1 if x not in [o1[y] for y in index]] any simpler solution for above lc? Thanks ...

Anyone else having trouble keeping ghettoq running inthe background with django-celery?

nohup python manage.py celeryd -f queue.log 2>queue.err 1>queue.out & Handles one request fine, then the client app posting the next job to the queues fails with this traceback. tasks.spawn_job.delay(details) File "/releases/env/lib/python2.6/site-packages/celery/task/base.py", line 321, in delay return self.apply_async(args, ...

Python urllib2 URLError http status code.

Hello, I want to grab the http status code once it raises a URLError exception: I tried this but didn't help: except URLError, e: logger.warning( 'It seems like the server is down. Code:' + str(e.code) ) ...

b = a vs b = a[:] in strings|lists

in Lists - I can always check that b=a points to same object and c=a[:] creates another copy. >>> a = [1,2,3,4,5] >>> b = a >>> c = a[:] >>> a[0] = 10 >>> b [10, 2, 3, 4, 5] >>> c [1, 2, 3, 4, 5] In Strings - I cannot make a change to the original immutable string. How do I confirm myself that b=a makes b point to same object, whi...

Testing Python console programs with Unicode strings in NetBeans 6.9

I try to run the following simple code in NetBeans 6.9 s = u"\u00B0 Celsius" print u"{0}".format(s) But I get the following error: UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 0: ordinal not in range(128) ...

Installing OSQA on Hostgator Shared

Hi Guys, Any idea how we can do this. i copied the files and enabled the python scripts when i try to run manage.py syncdb --all it gives error is there any guide how we can do this ? ...

xmlrpclib python - same script, different result

Hello, how can that happen that the same script produces different result on different machines (development & release)? Here is the script: import xmlrpclib print "ServerProxy" s = xmlrpclib.ServerProxy('http://jira.mycompany.com:80/rpc/xmlrpc') print "call get_tasks()..." ret_get_tasks = s.JiraVSB.get_tasks( "BDD", ["user"] ) print ...

Using recursion in Python class methods

Hello all, NB Noob alert ... ! I am trying to use recursion in a Python class method, but with limited results. I'm trying to build a car class, with very basic attributes: id, position in a one lane road (represented by an integer), and velocity. One of the functions I have is used to return which car id is in front on this one -- ...

what can cause pdb.set_trace() to be ignored?

I'm trying to debug a Python program and I inserted a classic 'import pdb;pdb.set_trace()' line in a function, just before a call which generates a stack trace. However that call seems to be ignored, i.e. nothing happens and I don't get a pdb prompt. At that point of the program, there is only one active thread. No monkey patching of t...

python generate SQL statement keywords by given lists

Hi ALL, I have below variables try to make an auto generating SQL statement in python _SQL_fields = ("ID", "NAME", "BIRTH", "SEX", "AGE") _add_SQL_desc_type = ("PRIMARY KEY AUTOINCREASEMENT",) _SQL_type = ("INT",'TEXT') _Value = (1,'TOM',19700101,'M',40) bop = ["AND"] * (len(_SQL_fields) - 1) m...

How to pass object_id to generic view object_detail in Django

I'm using django.views.generic.list_detail.object_detail. According to the documentation the view takes the variable object_id. To do this I added the following to my urlconf: (r'^(?P<object_id>\d+)$', list_detail.object_detail, article_info), The above line is in a separate urlconf that is included in the main urlconf. If I leave t...

Manipulating list from lxml xpath queries

Today I tried lxml as I got very nasty html output from particular web service, and I didn't want to go with re module, just for change and to learn something new. And I did, browsing http://codespeak.net/lxml/ and http://stackoverflow.com in parallel I won't try to explain above html template, but just for overview it's full of deliber...