User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 11:49 am

supra wrote:Using Model B 512MB, python3.2.3.3, 2014-01-07 wheezy raspbian
Does anyone knows how to convert from 2.7 to 3.2.3?

python2.x:

Code: Select all

data = (data & 0x0F)<< 4 #shift 4 bits to left 
I converted to python3.2.3:

Code: Select all

data = (data and 0x0F)<< 4 #shift 4 bits to left 
The error stating:
TypeError: unsigned operand type(s) for <<: 'NoneType' and 'int'
While I know nothing of Python 3, the use of 'and' instead of '&' as a bitwise operator is clearly incorrect. I suspect your Python 2 code is also correct in Python 3.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

User avatar
croston
Posts: 707
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 3:43 pm

What is 'data' and where did it come from?

User avatar
croston
Posts: 707
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 4:22 pm

Ok more precise question - what is type(data) ?

You need to make sure that data is an integer.

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 5:11 pm

When I wanted to run the code from one of Bruce Hall's PDFs I wrote an email to him (his address is in his PDF). He happily gave me a copy of his python code (for an 8x8 LED matrix in my case).

His code works just fine with Python 2. So I'd suspect you've introduced an error when you've cut 'n' pasted it from the PDF.

Why not write to Bruce?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 5:24 pm

This is where semantic white space is a right royal pain in the tail.

Combine that with the fact that Adobe Reader can't preserve white space and you may as well print the PDF pages and type the program in by hand (the way we used to do ZX80, ZX81, ZX Spectrum programs in the 1980s when the Internet didn't exist).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
chrisryall
Posts: 155
Joined: Wed Nov 27, 2013 11:45 am
Location: Wirral UK
Contact: Website

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 5:28 pm

coming from other languages, meaningful white space does seem pretty weird, and it is quite error/bug prone.

However it is what the language's progenitor wanted, we are stuck with it, and it does make the code look prettily "sepentine"

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 5:31 pm

chrisryall wrote:coming from other languages, meaningful white space does seem pretty weird, and it is quite error/bug prone.

However it is what the language's progenitor wanted, we are stuck with it, and it does make the code look prettily "sepentine"
Agreed, but I'd like all those hours chasing stupid bugs back when it's four spaces or a missing tab that caused them.
The worse thing is the colon on the conditional statements. The number of snytux errurs I've had from missing that is driving me towards writing everything on the RPi in C.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

robbes
Posts: 145
Joined: Sun Jan 20, 2013 7:11 pm
Location: Canada - off the west coast

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 5:43 pm

The worse thing is the colon on the conditional statements. The number of snytux errurs I've had from missing that is driving me towards writing everything on the RPi in C.
Any decent Python IDE should pick that up.

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 5:49 pm

robbes wrote:
The worse thing is the colon on the conditional statements. The number of snytux errurs I've had from missing that is driving me towards writing everything on the RPi in C.
Any decent Python IDE should pick that up.
You're assuming I would ever want to use anything other than vi (or editpad on Windows) to create python. You're wrong!
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
croston
Posts: 707
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 5:58 pm

@DougieLawson - can we assume that you have never missed a semicolon off the end of a statement in C? What about curly brackets or lack of curly brackets in as part of an if statement in C?

You can write horribly obfuscated and unmaintainable code in C if you are a sloppy programmer!

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 6:03 pm

It's not a problem with vi and C, vi does matching of parentheses, brackets and braces.

If you want to see my sloppy code you should look at the COBOL I write.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 6:35 pm

I write all my Python using either vi (on my Pi) or visual slick on my Windows machine. The latter always corrupts the tabbing even if it's visually correct. The last thing I do before running my code is to tabify it in IDLE - takes only 30s and gets rid of all those so difficult to find spacing bugs.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

User avatar
chrisryall
Posts: 155
Joined: Wed Nov 27, 2013 11:45 am
Location: Wirral UK
Contact: Website

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 7:41 pm

That's fine, and yes we should use IT to control bugs and errors in iT

Just a bit unbeautiful to set up a language that needs this a priori. And a clash with the principle that you should be able to tell what code does just be reading it through?

But I can cope: Had to revisit an XSLT file i did for my son's web site last week … talk about "write only" coding (and I had coded it)! Python (new, chez moi) rocks, in comparison.

keybeeper
Posts: 26
Joined: Wed Aug 08, 2012 10:15 am

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 7:44 pm

I used to write COBOL on special coding sheets and hand them to the punch-card girls for processing. The printed code was beautiful.

Now I find Geany very good for Python programming.

BTW why anyone writes new programs in Python2 is beyond me. I thought it was deprecated.
No Microsoft products were used in the creation of this message

User avatar
rpdom
Posts: 17172
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: bitwise operand from python2.7 to python3.2.3

Sun Jan 26, 2014 7:53 pm

I also used coding sheets to write programs in COBOL, but I didn't have to pass them to the punch room to be input as I had access to a terminal :)

The code was ugly, limited (although I found ways around some of that), and very long-winded. I preferred working in assembler whenever I could.

Return to “Python”