serial.write() method in pyserial seems to only send string data. I have arrays like [0xc0,0x04,0x00] and want to be able to send/receive them via the serial port? Are there any separate methods for raw I/O?
I think I might need to change the arrays to ['\xc0','\x04','\x00'], still, null character might pose a problem.
...
Given a dict, how can I find out if a given index in that dict has already been set to a non-None value?
I.e., I want to do this:
my_dict = {}
if (my_dict[some_value] != None):
my_dict[some_value] = 1
else:
my_dict[some_value] += 1
I.e., I want to increment the value if there's already one there, or set it to 1 otherwise.
...
Searching on Google reveals x2 code snippets. The first result is to this code recipe which has a lot of documentation and explanation, along with some useful discussion underneath.
However, another code sample, whilst not containing so much documentation, includes sample code for passing commands such as start, stop and restart. It al...
Hi,
Im making a small python script to upload files on the net. The script is working correctly, and now i want to add a simple progress bar that indicates the amount of uploading left. my question is -how do i get the upload status information from the server where im uploading the file, assuming it is possible...im using curl and pyc...
I have a bunch of Python modules in a directory, all being a derivate class. I need a "runner" script that, for each module, instantiate the class that is inside it (the actual class name can be built by the module file name) and than call the "go" method on each of them.
I don't know how many modules are there, but I can list all of th...
What's the easiest way to shuffle an array with python?
...
I'm working with PyGTK, trying to come up with a combination of widgets that will do the following:
Let me add an endless number of widgets in a column
Provide a vertical scrollbar to get to the ones that run off the bottom
Make the widgets' width adjust to fill available horizontal space when the window is resized
Thanks - I'm new t...
Hi!
I have several objects in the database. Url to edit an object using the generic view looks like site.com/cases/edit/123/ where 123 is an id of the particular object. Consider the cases/url.py contents:
url(r'edit/(?P<object_id>\d{1,5})/$', update_object, { ... 'post_save_redirect': ???}, name = 'cases_edit'),
where update_object i...
I think I am being a bonehead, maybe not importing the right package, but when I do...
from pysqlite2 import dbapi2 as sqlite
import types
import re
import sys
...
def create_asgn(self):
stmt = "CREATE TABLE ? (login CHAR(8) PRIMARY KEY NOT NULL, grade INTEGER NOT NULL)"
stmt2 = "insert into asgn values ('?', ?)"
sel...
I'm working on a macro system for Python (as discussed here) and one of the things I've been considering are units of measure. Although units of measure could be implemented without macros or via static macros (e.g. defining all your units ahead of time), I'm toying around with the idea of allowing syntax to be extended dynamically at r...
In a Python package, I have a string containing (presumably) the name of a subpackage. From that subpackage, I want to retrieve a tuple of constants...I'm really not even sure how to proceed in doing this, though.
#!/usr/bin/python
"" The Alpha Package
Implements functionality of a base package under the 'alpha' namespace
""
def get_p...
I have a text file that is encoded in UTF-8. I'm reading it in to analyze and plot some data. I would like the file to be read in as ascii. Would it be best to use the codecs module or use the builtin string decode method? Also, the file is divided up as a csv, so could the csv module also be a valid solution?
Thanks for your help.
...
I want to repeatedly execute a function in Python every 60 seconds forever (just like an NSTimer in Objective C). This code will run as a daemon and is effectively like calling the python script every minute using a cron, but without requiring that to be set up by the user.
In this question about a cron implemented in Python, the soluti...
Valve Software's Steam Server Query protocol as documented here allows you to query their game servers for various data. This is a little out of my depth and I'm looking for a little guidance as to what I need to learn.
I'm assuming I'll need socket and struct, correct?
I'm comfortable with basic UDP tasks like these, so I guess my ma...
Hello,
I have a 64 bit number comprised of various bit fields and I'm writing a simple python utility to parse the number. The problem I'm facing is that the lower 32 bits comprise of one field and using some combination of bit shifts or bit masking doesn't give just the 32 bits.
big_num = 0xFFFFFFFFFFFFFFFF
some_field = (big_num & ...
I declare this:
#This file is using encoding:utf-8
...
class Buddy(models.Model):
name=models.CharField('ФИО',max_length=200)
...
... in models.py. manage.py syncdb works smoothly. However when I go to admin interface and try to add a new Buddy I catch a DjangoUnicodeDecodeError, which says: "'utf8' codec can't decode bytes in...
If there is truly a 'best' way, what is the best way to ship a python app and ensure people can't (easily) reverse engineer your algorithms/security/work in general?
If there isn't a 'best' way, what are the different options available?
Background:
I love coding in Python and would love to release more apps with it. One thing that I w...
Hi again,
I have been working with postgreSQL, playing around with wikipedia's millions of hyperlinks and such, for 2 years now. I either do my thing directly by sending SQL commands, or I write a client side script in python to manage a million queries when this cannot be done productively (efficiently and effectively) manually.
I wo...
How can i create simple group by query in trunk version of django?
I need something like
SELECT name
FROM mytable
GROUP BY name
actually what i want to do is simply get all entries with distinct names.
...
How do these 2 classes differ?
class A():
x=3
class B():
def __init__(self):
self.x=3
Is there any significant difference?
...