I'm used to the Java model where you can have one public class per file. Python doesn't have this restriction, and I'm wondering what's the best practice for organising classes.
I have a file where the first byte contains encoded information. In Matlab I can read the byte bit by bit with var=fread(file,8, 'ubit1') then retrieve each bit by var(1),var(2), etc.
Is there any equivalent bit reader in python?
I'm trying to maximize a specific window with python...
Here is the deal:
I have a script that opens 2 firefox windows (selenium rc), and I need to maximize the second window, the last one that opens...
How can I do it?
I'm using this command
window = win32gui.GetForegroundWindow()
win32gui.MoveWindow(window, 0, 0, 1440, 900, True)
that works perfectly, but only with the focus window... and the second window of firefox witch opens with the script doesnt get focused...
Hi,
Is it possible using Python COM to select files inside of the windows explorer? For example, I am trying to get all "*.txt" files inside of windows explore highlighted without having to select them with the mouse, or without other keyboard gymnastics.
thanks in advance.
What are the advantages / disadvantages of using cooperative linux like portable ubuntu for example compared to a qemu or any other virtual machine installation. Is one option notably faster than the other plus and other things that should be taken into consideration.
Why does math.factorial act so weird in a thread?
Here is an example, it creates three threads:
thread that just sleeps for a while
thread that increments an int for a while
thread that does math.factorial on a large number.
It calls start on the threads, then join with a timeout
The sleep and spin threads work as expected and return from start right away, and then sit in the join for the timeout.
The factorial thread on the other hand does not return from start until it runs to the end!
import sys
from threading import Thread
from time import sleep, time
from math import factorial
# Helper class that stores a start time to compare to
class timed_thread(Thread):
def __init__(self, time_start):
Thread.__init__(self)
self.time_start = time_start
# Thread that just executes sleep()
class sleep_thread(timed_thread):
def run(self):
sleep(15)
print "st DONE:\t%f" % (time() - time_start)
# Thread that increments a number for a while
class spin_thread(timed_thread):
def run(self):
x = 1
while x < 120000000:
x += 1
print "sp DONE:\t%f" % (time() - time_start)
# Thread that calls math.factorial with a large number
class factorial_thread(timed_thread):
def run(self):
factorial(50000)
print "ft DONE:\t%f" % (time() - time_start)
# the tests
print
print "sleep_thread test"
time_start = time()
st = sleep_thread(time_start)
st.start()
print "st.start:\t%f" % (time() - time_start)
st.join(2)
print "st.join:\t%f" % (time() - time_start)
print "sleep alive:\t%r" % st.isAlive()
print
print "spin_thread test"
time_start = time()
sp = spin_thread(time_start)
sp.start()
print "sp.start:\t%f" % (time() - time_start)
sp.join(2)
print "sp.join:\t%f" % (time() - time_start)
print "sp alive:\t%r" % sp.isAlive()
print
print "factorial_thread test"
time_start = time()
ft = factorial_thread(time_start)
ft.start()
print "ft.start:\t%f" % (time() - time_start)
ft.join(2)
print "ft.join:\t%f" % (time() - time_start)
print "ft alive:\t%r" % ft.isAlive()
And here is the output on Python 2.6.5 on CentOS x64:
sleep_thread test
st.start: 0.000675
st.join: 2.006963
sleep alive: True
spin_thread test
sp.start: 0.000595
sp.join: 2.010066
sp alive: True
factorial_thread test
ft DONE: 4.475453
ft.start: 4.475589
ft.join: 4.475615
ft alive: False
st DONE: 10.994519
sp DONE: 12.054668
I've tried this on python 2.6.5 on CentOS x64, 2.7.2 on Windows x86 and the factorial thread does not return from start on either of them until the thread is done executing.
I've also tried this with PyPy 1.8.0 on Windows x86, and there result is slightly different. The start does return immediately, but then the join doesn't time out!
sleep_thread test
st.start: 0.001000
st.join: 2.001000
sleep alive: True
spin_thread test
sp.start: 0.000000
sp DONE: 0.197000
sp.join: 0.236000
sp alive: False
factorial_thread test
ft.start: 0.032000
ft DONE: 9.011000
ft.join: 9.012000
ft alive: False
st DONE: 12.763000
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 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 would like my TrueCrypt virtual drive to act as a newly inserted USB drive or CD/DVD by executing commands in the partition's autorun.inf file.
I've read several suggestions online including creating a .bat file or installing software so Windows will think this is a CD, but I'd like to know the easiest and least intrusive way to pull it off. i.e. I want to keep from installing or messing with the host computer as much as possible, as this is intended to be a fully portable drive.
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 ;)
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)
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?
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,
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 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 looking for a static analysis tool for Python, 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 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!
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?
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'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.
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.