Just beginning with python and know enough to know I know nothing. I would like to find alternative ways of splitting a list into a list of dicts. Example list:
data = ['ID:0:0:0',
'Status:Ok',
'Name:PhysicalDisk0:0:0',
'State:Online',
'FailurePredicted:No',
'ID:0:0:1',
'Status:Ok',
...
Python and SendKeys
import SendKeys, threading, pyHook, pythoncom
class Auto(threading.Thread):
def run(self):
SendKeys.SendKeys("{ENTER}",pause=0.1);
print('Sent');
exit();
def OnKeyboardEvent(event):
if event.Ascii == 22:
Auto().start();
return True
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEven...
I've got a few questions about best practices in Python. Not too long ago I would do something like this with my code:
...
junk_block = "".join(open("foo.txt","rb").read().split())
...
I don't do this anymore because I can see that it makes code harder to read, but would the code run slower if I split the statements up like so:
f_obj...
I wanna learn how to build a p2p application in python that conforms to the gnutella protocol so it can tap-in the existing network like limewire, etc.
Any body who knows something where to start or a ste-by-step guide? I've been reading the http://wiki.limewire.org/index.php?title=GDF but I need something with an example so I can easil...
In the following code:
class ClassA(db.Model):
name = db.StringProperty()
class ClassB(db.Model):
name = db.StringProperty()
deleted_flag = db.BooleanProperty()
classA = db.ReferenceProperty(ClassA)
ClassA will have a property called classb_set. When I call classb_set within code, I do not want it to return items tha...
my code run wrong,i don't know why
class a:
def __get__(self):
return 'xxx'
def aa(self):
print 'aaaa'
b=a()
print b.get('aa')
Please try to use the code, rather than text, because my English is not very good, thank you
#
class HideX(object):
def __init__(self, x):
self.x = x
def get_x(self...
How to read/write a .sit archive using Python in Linux?
...
Does anyone know a spiffy way to use C header files in Python? For example I have a C program that includes a global variable:
typedef struct ImageInfo
{
uint8_t revisionMajor;
uint8_t revisionMinor;
uint16_t checksum;
} ImageInfo;
ImageInfo gImageInfo; /* Placed at a specific address by the linker */
I would like ...
I want to do the equivalent of
class Foo(object):
bar = 1
using Python's C API. In other words, I want to create a Python class which has a static variable, using C.
How can I do this?
...
Is there a method like isiterable? The only solution I have found so far is to call
getattr(myObj, '__iter__', False)
But I am not sure how fool-proof this is.
...
Is there a way so that I can get access to request object, while saving a db object, without explicitly passing it e.g.
class RequestData(db.Model):
...
def put(self):
# autopopulate fields from current request
I just want a quick way to access request, instead of passing it thru so many layers of view/forms/etc
...
Hello,
I am trying to set up an email function that will email the last 15 lines of a results.txt file in python. I am not sure how to do this and was asking do I have to connect to an email server or does python have some other way of sending email. The code below is what i have got so far and any help would be appreciated. Thanks
imp...
I have two lists like:
list1 = ['square','circle','triangle']
list2 = ['red','green']
How can I create all permutations of these lists, like this:
[
'squarered', 'squaregreen',
'redsquare', 'greensquare',
'circlered', 'circlegreen',
'redcircle', 'greencircle',
'trianglered', 'trianglegreen',
'redtriangle', 'greentriangle'...
If I have a scenario where an exception is raised, caught, then raised again inside the except: block, is there a way to capture the initial stack frame from which it was raised?
The stack-trace that gets printed as python exits describes the place where the exception is raised a second time. Is there a way to raise the exception suc...
I get the following error when using multiprocessing:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner
self.run()
File "/usr/lib/python2.6/threading.py", line 477, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python...
I wrote a small web server using wsgiref.simple_server in python. It get and parse request via URL (environ.get('PATH_INFO')). Data return in xml format. I've test it, everything ok before return to client, xml string no problem (using print xml to view before return). With Firefox, IE, sometimes xml string show in FF, IE has error:
XML...
Guys,
I have dictionary and would like to produce html page where will be drawn simple html table with keys and values. How it can be done from python code?
...
Hi everyone,
I'm currently coding a project in python where I need a sort of cache of generic objects, I have settled on using WeakValueDictionaries for this. These generic objects are often referenced by many other non-generic objects. My main problem though is that I can't seem to wrap my head around a way of making these WeakValueDic...
Hello all,
Question in nutshell
What is the best way to get Python and Java to play nice with each other?
More detailed explanation
I have a somewhat complicated situation. I'll try my best to explain both in pictures and words. Here's the current system architecture:
We have an agent-based modeling simulation written in Java. ...
How can one access NS attributes through using ElementTree?
With the following:
<data xmlns="http://www.foo.net/a" xmlns:a="http://www.foo.net/a" book="1" category="ABS" date="2009-12-22">
When I try to root.get('xmlns') I get back None, Category and Date are fine, Any help appreciated..
...