| JREF Homepage | Swift Blog | Events Calendar | $1 Million Paranormal Challenge | The Amaz!ng Meeting | Useful Links | Support Us |
![]() |
|
|
|
|||||||
| Notices |
| Welcome to the JREF Forum, where we discuss skepticism, critical thinking, the paranormal and science in a friendly but lively way. You are currently viewing the forum as a guest, which means you are missing out on discussing matters that are of interest to you. Please consider registering so you can gain full use of the forum features and interact with other Members. Registration is simple, fast and free! Click here to register today. |
|
|
#1 |
|
Sarcastic Conqueror of Notions
Join Date: Mar 2004
Location: A floating island above the clouds
Posts: 23,835
|
When I read some binary data with pySerial, I get an str that contains elements that, when printed, look like this:
'\xc0' That itself is a str. How do I turn it back into a number so I can do math on it? o int( '\xc0' ) chokes o The binascii library is useless as it can't handle this in any of its format conversions. As these are bytes, I could conceivably do 256-sized lookup table, but that's obviously stupid to do. I am not super familiar with Python, yet, having only started a few days ago. The result should be amenable to simple math, like adding or subtracting 3. |
|
__________________
"Great innovations should not be forced [by way of] slender majorities." - Thomas Jefferson The government should nationalize it! Socialized, single-payer video game development and sales now! More, cheaper, better games, right? Right? |
|
|
|
|
|
#2 |
|
Nap, interrupted.
Join Date: Aug 2001
Location: a little toolshed
Posts: 18,634
|
The ord() method returns the Unicode code for the character in a string of length 1. I think that should do the trick.
~~ Paul |
|
__________________
Millions long for immortality who do not know what to do with themselves on a rainy Sunday afternoon. ---Susan Ertz RIP Mr. Skinny |
|
|
|
|
|
#3 |
|
Sarcastic Conqueror of Notions
Join Date: Mar 2004
Location: A floating island above the clouds
Posts: 23,835
|
Byte array objects, pickler, jeebus...
ord('\xc0') ==> 192 Thanks, Paul! |
|
__________________
"Great innovations should not be forced [by way of] slender majorities." - Thomas Jefferson The government should nationalize it! Socialized, single-payer video game development and sales now! More, cheaper, better games, right? Right? |
|
|
|
|
|
#4 |
|
Nap, interrupted.
Join Date: Aug 2001
Location: a little toolshed
Posts: 18,634
|
It all pales into insignificance against the backdrop of a whitespace language.
Code:
for n in range(2, 10):
for x in range(2, n):
if n % x == 0:
print n, 'equals', x, '*', n/x
print tracing info
break
else:
print n, 'is a prime number'
~~ Paul |
|
__________________
Millions long for immortality who do not know what to do with themselves on a rainy Sunday afternoon. ---Susan Ertz RIP Mr. Skinny |
|
|
|
|
|
#5 |
|
Sarcastic Conqueror of Notions
Join Date: Mar 2004
Location: A floating island above the clouds
Posts: 23,835
|
Ahh, another question, If I may?
Wut? Code:
>>> class abc:
def __init__(self):
print "abc.__init__ called!"
>>> x = abc.abc()
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
x = abc.abc()
AttributeError: class abc has no attribute 'abc'
>>> x = abc.__class()
Traceback (most recent call last):
File "<pyshell#46>", line 1, in <module>
x = abc.__class__()
AttributeError: class abc has no attribute '__class__'
>>>
Ok, figured it out. The reason is Dive Into Python, the online tutorial, saves their class in a module named the same thing, but with lower case for module name. This works: Code:
>>> x = abc() abc.__init__ called! >>> x <__main__.abc instance at 0x011C2D78> >>> Apparently the Dive Into Python example was thus doing the equivalent of x = ABC.abc(), where the first abc is the module name. |
|
__________________
"Great innovations should not be forced [by way of] slender majorities." - Thomas Jefferson The government should nationalize it! Socialized, single-payer video game development and sales now! More, cheaper, better games, right? Right? Last edited by Beerina; 22nd June 2010 at 06:45 AM. Reason: Forgot self arg in __init__, but it didn't change the result. |
|
|
|
|
|
#6 |
|
Atheist for Jesus
Join Date: Feb 2007
Posts: 645
|
Damn, I thought the OP meant I could quote lines from the "Holy Grail" and such....
Wrong Python....
|
|
|
|
|
#7 |
|
Sarcastic Conqueror of Notions
Join Date: Mar 2004
Location: A floating island above the clouds
Posts: 23,835
|
Code:
>>> for n in range(1,100): print "Spam" Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam Spam >>> |
|
__________________
"Great innovations should not be forced [by way of] slender majorities." - Thomas Jefferson The government should nationalize it! Socialized, single-payer video game development and sales now! More, cheaper, better games, right? Right? |
|
|
|
|
|
#8 |
|
Sarcastic Conqueror of Notions
Join Date: Mar 2004
Location: A floating island above the clouds
Posts: 23,835
|
Ok, next question:
I am trying to use makepy.py to access a COM-interfaced library. Several web sites say to do this to see what's available: e.g. here:
Quote:
>>> import win32com.client >>> win32com\client\makepy.py <---- Red rectangle starts after the y in .py SyntaxError: unexpected character after line continuation character >>> makepy.py exists in the relevant win32com\client directory "C:\Python26\Lib\site-packages\win32com\client" Any ideas? I get the same result typing the line in manually, in case copy-paste from the web site captured some bizarre character codes. Note I am not looking for a general tutorial on COM and Python (that's what that page is) just wondering about what I could be doing wrong. |
|
__________________
"Great innovations should not be forced [by way of] slender majorities." - Thomas Jefferson The government should nationalize it! Socialized, single-payer video game development and sales now! More, cheaper, better games, right? Right? |
|
|
|
|
|
#9 |
|
Sarcastic Conqueror of Notions
Join Date: Mar 2004
Location: A floating island above the clouds
Posts: 23,835
|
Well, you have to run it from the command prompt:
C:\Python26\Lib\site-packages\win32com\client\makepy.py |
|
__________________
"Great innovations should not be forced [by way of] slender majorities." - Thomas Jefferson The government should nationalize it! Socialized, single-payer video game development and sales now! More, cheaper, better games, right? Right? |
|
|
|
|
|
#10 |
|
New Blood
Join Date: Apr 2009
Location: San Francisco, CA
Posts: 20
|
This simply isn't valid python:
>>> win32com\client\makepy.py If you're trying to run that, you need to do it from a command prompt, not a Python interactive prompt. |
|
|
|
|
#11 |
|
Scholar
Join Date: Jul 2010
Location: San Francisco, CA
Posts: 106
|
|
|
|
|
|
#12 |
|
Gazerbeam's Protege
Join Date: Apr 2006
Location: The Mended Drum
Posts: 5,631
|
I don't know the first thing about programming, but I'd like to put a plug in for my best friend, Mark Pilgrim, who wrote a book (several, actually) called Dive Into Python. He's quite a good writer. It's available in print or online. Google it, and him.
|
|
__________________
I wish someone would find something I wrote on this board to be sig-worthy, thereby effectively granting me immortality.--Antiquehunter The gods do not deduct from a man's allotted years on earth the time spent eating butterscotch pudding. AMERICA! NUMBER 1 IN PARTICLE PHYSICS SINCE JULY 4TH, 1776!!! --SusanConstant |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|