I haven’t been able to find a good solution for this problem on the net (probably because switch, position, list and Python are all such overloaded words).
It’s rather simple – I have this list:
['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter']
I’d like to switch position of 'password2' and 'password1' – not knowing their exact position, only that they’re right next to one another and password2 is first.
I’ve accomplished this with some rather long-winded list-subscripting, but I wondered if someone could come up with something a bit more elegant?
Hi, for development i'd love to have a flat file database with the requirements up in the title, but I don't seem to be able to find a database with these requirements. I can't seem to get MetaKit to work. I only need it to work on the development machine, but in the real world my product will have more data and needs more room and will need something better.
Does anyone know of a database engine capable of this or do I need to just use python's pickle and load and save a file?
Joe
I want to create a list of integers from 1 to n. I can do this in Python using range(1, n+1), and in Haskell using: take n (iterate (1+) 1).
What is the right OCaml idiom for this?
Hello,
it gives me this error:
Traceback (most recent call last):
File "C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Plugins\NoisePlugin.py", line 113, in onPaint
dc.DrawLine(valueWI, valueHI, valueWF, valueHF)
File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py", line 3177, in DrawLine
return _gdi_.DC_DrawLine(*args, **kwargs)
OverflowError: cannot convert float infinity to integer
How can I avoid this to happen?
Thanks in advance ;)
Python language has a well known feature named interactive mode where interpreter can read commands directly from tty.
I tipically use this mode to test if a given module is in the classpath or to play around and test some snippets.
Do you know any other programming languages that has Interactive Mode?
I'm trying to create a shell like environment, where a user is presented with "" and can type in any of a number of pre-defined commands. However, the only way I can think of implementing this is with a dictionary mapping commands-code and python's "exec".
Is there a more correct way of doing this?
More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?
(My google-fu seems to have let me down on this one.)
Related:
Enumerating all available drive letters in Windows (C++ / Win32)
How do I set a GChat or jabber status via python? Right now I've got this:
import xmpp
new_status = "blah blah blah"
login = 'email'
pwd = 'password'
cnx = xmpp.Client('gmail.com')
cnx.connect( server=('talk.google.com',5223) )
cnx.auth(login, pwd, 'botty')
pres = xmpp.Presence()
pres.setStatus(new_status)
cnx.send(pres)
It executes, but the status is not updated. I know I'm connecting to the server successfully, as I can send chat messages to others. What am I doing wrong here?
I'm trying to serve a merurial repository with apache, and when I try to push to the repo I see this in the apache error.log. On the client side I get a 500 error.
How do I get this to go away????
[Sun Jun 06 14:43:25 2010] [error] [client 192.168.1.8] /var/lib/python-support/python2.6/mercurial/hgweb/common.py:24: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
[Sun Jun 06 14:43:25 2010] [error] [client 192.168.1.8] self.message = message
[Sun Jun 06 14:43:25 2010] [error] [client 192.168.1.8] /var/lib/python-support/python2.6/mercurial/hgweb/hgweb_mod.py:104: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
[Sun Jun 06 14:43:25 2010] [error] [client 192.168.1.8] if not inst.message:
[Sun Jun 06 14:43:25 2010] [error] [client 192.168.1.8] /var/lib/python-support/python2.6/mercurial/hgweb/hgweb_mod.py:106: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
[Sun Jun 06 14:43:25 2010] [error] [client 192.168.1.8] return '0\\n%s\\n' % inst.message,
I love the IDLE. However, sometimes I have 100-200 line scripts and I want to sort of interactively debug/play with say, functions defined in foo.py instead of just calling python foo.py. Is there a way I can trigger IDLE in the context of my foo.py?
I am having a hard time figuring out a reasonable way to generate a mixed-case hash in Python.
I want to generate something like: aZeEe9E
Right now I'm using MD5, which doesn't generate case-sensitive hashes.
What is a good way to generate a hash value consisting of upper- and lower- case characters + numbers?
I am looking for a static analysis tool forPython, Ruby, Sql, Cobol, Perl, PL/SQL, SQL similar to find bugs and check style. I am looking for calculating the line count, identify bugs during the development, and enforcing coding standard.
I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.
What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.
I'll likely run Ubuntu 9.10, but I'm flexible. If Windows is a better option, that's fine too.
Hi guys,
So I am relatively new to Python and I am having trouble working with 2D Lists.
Here's my code:
data = [[None]*5]*5
data[0][0] = 'Cell A1'
print data
and here is the output (formatted for readability):
[['Cell A1', None, None, None, None],
['Cell A1', None, None, None, None],
['Cell A1', None, None, None, None],
['Cell A1', None, None, None, None],
['Cell A1', None, None, None, None]]
Why does every row get assigned the value?
I love the IDLE. However, sometimes I have 100-200 line scripts and I want to sort of interactively debug/play with say, functions defined in foo.py instead of just calling python foo.py. Is there a way I can trigger IDLE in the context of my foo.py?
I would like to port this question to Python (Windows + Linux + Mac Os)
http://stackoverflow.com/questions/2725529/how-to-create-ascii-animation-in-windows-console-application-using-c
Thank you!
From the Python 2.6 shell:
>>> import sys
>>> print sys.getdefaultencoding()
ascii
>>> print u'\xe9'
é
>>>
I expected to have either some gibberish or an Error after the print statement, since the "é" character isn't part of ASCII and I haven't specified an encoding. I guess I don't understand what ASCII being the default encoding means.
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?
Given a string "VAR=value" I want to split it at the first '=' sign, something like this:
var, sep, value = "VAR=value".partition('=')
Is there a way to NOT declare a variable 'sep'? Like this (just made up the syntax):
var, -, value = "VAR=value".partition('=')
Just for completeness, I'm targetting Python v 2.6
For a long time I was using Python 2.5 to do all this fine but recently upgraded to 2.7 since building stuff for 2.5 is a real pain. I also updated mod_wsgi to 3.3 forPython 2.7.
Everything is working fine with Apache + mod_wsgi on CentOS and also in the Django runserver on both Windows and CentOS, but not with Apache + mod_wsgi on Windows.
Whenever I try to access a page in my Django app I get the following (note that Apache starts fine):
ImportError at /
DLL load failed: The specified module could not be found.
Which is caused by things like:
from Crypto.Cipher import AES
Etree and others cause the exact same error and it is not limited to any specific packages. Anything with pyd files fails.
Googling around suggests reinstalling Python "for all users", but the installer doesn't give you that option anymore anyway. For good measure I've tried reinstalling Python 2.7 as an administrator and also told it to register itself as the default version of Python but neither helped.
I think the solution might have something to do with:
The fact that I have 2.5, 2.6 and 2.7 installed on this machine and mod_wsgi might be loading the DLLs for 2.5 instead of 2.7.
Something to do with WSGIPythonPath, which I usually don't need to set.
I want to write a simple python script that send a EML file exported from Outlook though given smtp server as email to a given list of emails. I know how to send a simple email but sending a EML file as email is not something i could do and could not find it on Google. Can anyone help me with that. The EML file is actually in HTML format with embedded images. Any alternate suggestion is also welcome.
I am porting code from Matlab to Python and am having trouble finding a replacement for the firls( ) routine. It is used for, least-squares linear-phase Finite Impulse Response (FIR) filter design.
I looked at scipy.signal and nothing there looked like it would do the trick. Of course I was able to replace my remez and freqz algorithsm, so that's good.
On one blog I found an algorithm that implemented this filter without weighting, but I need one with weights.
Thanks, David
I have both Fruityloops and Propellerheads Reason software synths on my Windows PC.
Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code?
Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) don't seem to work. I don't think Reason or FL Studio act like standard GM Midi synths.
Update 2 : If you're interested in this question, check out this too.
Whenever I change my python source files in my Django project, the .pyc files become out of date. Of course that's because I need to recompile them in order to test them through my local Apache web server. I would like to get around this manual process by employing some automatic means of compiling them on save, or on build through Eclipse, or something like that. What's the best and proper way to do this?