JREF Homepage Swift Blog Events Calendar $1 Million Paranormal Challenge The Amaz!ng Meeting Useful Links Support Us
James Randi Educational Foundation JREF Forum
Forum Index Register Members List Events Mark Forums Read Help

Go Back   JREF Forum » General Topics » Computers and the Internet
Click Here To Donate

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.

Tags programming , python

Reply
Old 15th June 2010, 02:32 PM   #1
Beerina
Sarcastic Conqueror of Notions
 
Beerina's Avatar
 
Join Date: Mar 2004
Location: A floating island above the clouds
Posts: 23,835
Post Anyone know Python?

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?
Beerina is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 15th June 2010, 02:37 PM   #2
Paul C. Anagnostopoulos
Nap, interrupted.
 
Paul C. Anagnostopoulos's Avatar
 
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
Paul C. Anagnostopoulos is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 15th June 2010, 02:38 PM   #3
Beerina
Sarcastic Conqueror of Notions
 
Beerina's Avatar
 
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?

Last edited by Beerina; 15th June 2010 at 02:39 PM.
Beerina is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 15th June 2010, 04:53 PM   #4
Paul C. Anagnostopoulos
Nap, interrupted.
 
Paul C. Anagnostopoulos's Avatar
 
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'
Screwed and screwed again.

~~ Paul
__________________
Millions long for immortality who do not know what to do with themselves on a rainy Sunday afternoon. ---Susan Ertz

RIP Mr. Skinny
Paul C. Anagnostopoulos is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 22nd June 2010, 06:38 AM   #5
Beerina
Sarcastic Conqueror of Notions
 
Beerina's Avatar
 
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.
Beerina is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 22nd June 2010, 06:41 AM   #6
Greediguts
Atheist for Jesus
 
Greediguts's Avatar
 
Join Date: Feb 2007
Posts: 645
Damn, I thought the OP meant I could quote lines from the "Holy Grail" and such....


Wrong Python....
Greediguts is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 29th June 2010, 06:45 AM   #7
Beerina
Sarcastic Conqueror of Notions
 
Beerina's Avatar
 
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?

Last edited by Beerina; 29th June 2010 at 06:46 AM.
Beerina is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 12th July 2010, 02:48 PM   #8
Beerina
Sarcastic Conqueror of Notions
 
Beerina's Avatar
 
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:
Example using Microsoft Office 97.

Either:

Run 'win32com\client\makepy.py' (eg, run it from the command window, or double-click on it) and a list will be presented. Select the Type Library 'Microsoft Word 8.0 Object Library'
But I get this:

>>> 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?

Last edited by Beerina; 12th July 2010 at 02:54 PM.
Beerina is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 12th July 2010, 02:56 PM   #9
Beerina
Sarcastic Conqueror of Notions
 
Beerina's Avatar
 
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?
Beerina is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 12th July 2010, 05:55 PM   #10
kylev
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.
kylev is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 16th July 2010, 07:33 PM   #11
KirinDave
Scholar
 
Join Date: Jul 2010
Location: San Francisco, CA
Posts: 106
Originally Posted by Paul C. Anagnostopoulos View Post
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'
Screwed and screwed again.

~~ Paul
Hey wow. There might be sane compsci types here. Down with significant whitespace. Down with that puny lambda.
KirinDave is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 16th July 2010, 08:17 PM   #12
NobbyNobbs
Gazerbeam's Protege
 
NobbyNobbs's Avatar
 
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
NobbyNobbs is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Reply

JREF Forum » General Topics » Computers and the Internet

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 03:04 AM.
Powered by vBulletin. Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
© 2001-2012, James Randi Educational Foundation. All Rights Reserved.

Disclaimer: Messages posted in the Forum are solely the opinion of their authors.