Re: [Tutor] decision structures

2008-10-20 Thread Brian Lane
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

bob gailer wrote:
> Brummert_Brandon wrote:
>> Hello.  I am working with python for computer science this semester.  I am 
>> having a difficult time on one of my lab assignments.  It is in the python 
>> programming book in chapter 7 under decision structures.  I am being asked 
>> to write a program in that accepts a date in the form month/date/year and 
>> outputs whether the date is valid.  For example, 5/24/1962 is valid but 
>> 9/31/2000 is not because September only has 30 days.  
> "the python programming book"? There are a lot of these. Which one do 
> you refer to?
> 
> Regarding homework - we can offer specific help, when we see your 
> efforts and where you are stuck. Have you written any Python code for 
> this assignment? Or any program design?
> 
> Do you know how to do input and output? How to split a string? How to 
> convert characters to numbers? How to compare numbers? How to create and 
> use lists of numbers? Those are the skills you need for this problem. 
> Give it a stab and report back and let's see what happens.
> 

I'd look into learning how to use the datetime module.

Brian

- --
- ---[Office 71.0F]--[Outside 39.9F]--[Server 104.6F]--[Coaster 72.0F]---
- ---[CACHALOT (366764080) @ 47 29.9424 -122 28.8851]---
Software, Linux, Microcontrollers http://www.brianlane.com
AIS Parser SDKhttp://www.aisparser.com

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)
Comment: Remember Lexington Green!

iD8DBQFI/XHtIftj/pcSws0RAgeGAJ9zMSVrV7rbr1WrWEsZw1liPTGmEQCfQdMb
p2fUPyV3LXDnj1LRUxBJvyg=
=A7eC
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] auto referer handler/opener for urlib2?

2008-10-20 Thread xbmuncher
I was reading about urllib2 openers.. Can I make any kind of def or function
and make the urllib2 "urlopen" function run through this function first
before opening a url? For example, something like a reporthook function.
What I want to do is this:

def autoReferer(handle):
if handle.lastRequest.url != None:
handle.addheader('referer' : handle.lastRequest.url)


How can make this auto referer functionality with urllib2?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decision structures

2008-10-20 Thread bob gailer

Brummert_Brandon wrote:
Hello.  I am working with python for computer science this semester.  I am having a difficult time on one of my lab assignments.  It is in the python programming book in chapter 7 under decision structures.  I am being asked to write a program in that accepts a date in the form month/date/year and outputs whether the date is valid.  For example, 5/24/1962 is valid but 9/31/2000 is not because September only has 30 days.  
"the python programming book"? There are a lot of these. Which one do 
you refer to?


Regarding homework - we can offer specific help, when we see your 
efforts and where you are stuck. Have you written any Python code for 
this assignment? Or any program design?


Do you know how to do input and output? How to split a string? How to 
convert characters to numbers? How to compare numbers? How to create and 
use lists of numbers? Those are the skills you need for this problem. 
Give it a stab and report back and let's see what happens.


--
Bob Gailer
Chapel Hill NC 
919-636-4239


When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.


Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] decision structures

2008-10-20 Thread Brummert_Brandon


Hello.  I am working with python for computer science this semester.  I am 
having a difficult time on one of my lab assignments.  It is in the python 
programming book in chapter 7 under decision structures.  I am being asked to 
write a program in that accepts a date in the form month/date/year and outputs 
whether the date is valid.  For example, 5/24/1962 is valid but 9/31/2000 is 
not because September only has 30 days.  Thank you.


Brandon Brummert
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multiple lists from single list with nested lists

2008-10-20 Thread Kent Johnson
On Mon, Oct 20, 2008 at 5:33 PM, Sander Sweers <[EMAIL PROTECTED]> wrote:
> Hi, I am learning myself python and I need to create 2, or more but
> let's use 2 as an example, lists from a list with nested lists.
>
> For example the below,
>
> ['Test1', 'Text2', ['1', '2'], 'Text3']
>
> Should result in,
>
> [['Test1', 'Text2', '1', 'Text3'],
> ['Test1', 'Text2', '2', 'Text3']
>
> I though of using a temp list and looping over the list twice, something like,
>
> somelist = ['Test1', 'Text2', ['1', '2'], 'Text3']
> templist = []
> for x in range(len(somelist[2])):
>templist.append([somelist[0], somelist[1], somelist[2][x], somelist[3]])

Is it always just the third item that is a list? If so I think your
solution is not too bad. You could write it as
templist = []
for x in somelist[2]):
   templist.append(somelist[0:2] + [x] + somelist[3:])

or use a list comprehension:
templist = [ somelist[0:2] + [x] + somelist[3:] for x in somelist ]

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] String and integer

2008-10-20 Thread wesley chun
>> def nr():
>>nr1 = input('Enter value: ')
>>print str(nr1).strip('nr0')
>>
>> The user input is always on the form "nr08756" and i'd like to take out
>> the "nr0" and then print the result.
>> I can see that there is a problem with a variable looking like "pn0123"
>> because i get: NameError: global name 'nr0123' is not defined.
>>
>> What is the right way to do this?
>
> raw_input() rather than input(). input evaluate whatever is entered;
> raw_input returns as a string whatever is entered.
>
> In Python 3 raw_input will be renamed input and the old input will go away.


everything that bob said... and more.  :-)

definitely never ever use input()... it is absolutely unnecessary and
a potential security hazard, hence the reason why its functionality
will be completely removed in 3.0. for now, as bob has suggested, use
raw_input() in the remaining 2.x releases then switch to input() for
3.x.

with regards to the rest of your query, if you are certain that the
first few chars of the input is 'nr0', you can just so nr1[3:] to get
the rest. if you want to play it safe, throw in a "if
nr1.startswith('nr0')" beforehand.

finally, be careful with strip(). you are not stripping just the "nr0"
with strip('nr0')... you are removing all 'n's, 'r's, and '0's from
your string, i.e.

>>> 'nr07890'.strip('nr0')
'789'

this is the reason why i suggested nr1[3:] instead... it chops off the
1st 3 chars and takes the remainer.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] String and integer

2008-10-20 Thread bob gailer

Jens Frid wrote:

Hi,
the code is:

def nr():
nr1 = input('Enter value: ')
print str(nr1).strip('nr0')

The user input is always on the form "nr08756" and i'd like to take 
out the "nr0" and then print the result.
I can see that there is a problem with a variable looking like 
"pn0123" because i get: 
NameError: global name 'nr0123' is not defined.


What is the right way to do this?


raw_input() rather than input(). input evaluate whatever is entered; 
raw_input returns as a string whatever is entered.


In Python 3 raw_input will be renamed input and the old input will go away.


Thanks!


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  



--
Bob Gailer
Chapel Hill NC 
919-636-4239


When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.


Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to see a number as two bytes

2008-10-20 Thread Alan Gauld

"shawn bright" <[EMAIL PROTECTED]> wrote


i have a script that needs to send a number as two bytes.
how would i be able to see a number expressed as a hi byte and a lo 
byte?


One way is to use the struct module.
It has the advantage of allowing selection of big endian(>) or little
endian(<) representation etc. The H symbol can be used for a short
integer - ie 2 bytes...

eg


import struct
b = struct.pack(">H", 279)
b

'\x01\x17'

b = struct.pack("
'\x17\x01'




Note that Python will print bytes with printable representations as
the character form but the data is still two bytes.

eg

struct.pack("H", 33)

'!\x00'

chr(33)

'!'


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] finding numbers in range of of numbers

2008-10-20 Thread W W
On Mon, Oct 20, 2008 at 5:19 PM, Srinivas Iyyer
<[EMAIL PROTECTED]>wrote:

> dear group,
> a simple question that often challenges me.
>
> I have
>
> I have a list of list:
>
> [[10,45],[14,23],[39,73],[92,135]]
>
> I want to identify if any of the items in this list are in range of [5,100]
>
> These numbers are large in original data, I will be using xrange for memory
> issues.
>
>  thank you.
> srini


a simple comparison should do it for ya,
HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which exceptions should I be catching?

2008-10-20 Thread W W
On Mon, Oct 20, 2008 at 4:36 PM, Wesley Brooks <[EMAIL PROTECTED]> wrote:

> That's why you should write an error log ;)
>
>
> The error log is a valid point. Is there a way to capture the error
> messages that go the the terminal window or command prompt rather than all
> my print statements? Can this be set up as a global thing for the whole
> application rather than inside each thread?
>
> try:
>> put your function here
>> except:
>> print 'oops! an error occurred!'
>>
>
> I'll probably resort to this and have done in a couple of other occasions,
> but thought it was generally frowned upon! I Guess I could do that and print
> out anything caught by the exception into a log and go more specific at a
> later date.
>
> Cheers,
>
> Wesley Brooks
>
>
>
>> On Mon, Oct 20, 2008 at 3:30 PM, Wesley Brooks <[EMAIL PROTECTED]>wrote:
>>
>>> Unfortunately due to the nature of the program the error has normally
>>> happened hours ago and the error message has disappeared from the buffer of
>>> the command prompt.
>>>
>>
>> That's why you should write an error log ;)
>>
>>
>>>
>>> This is the function:
>>>
>>> def CommandFileWriter(self, command):
>>>   name1 = os.path.join(self.commandsdir, command + '.temp')
>>>   name2 = os.path.join(self.commandsdir, command)
>>>   comfile = open(name1, 'w')
>>>   comfile.close()
>>>   if not os.path.exists(name2):
>>> os.rename(name1, name2)
>>>   else:
>>> os.remove(name1)
>>>
>>> This was the best way I could come up with doing the function. So the
>>> file is written to the correct directory with a wrong name (so the other
>>> program will ignore it) then it's name is changed to the correct name with
>>> os.rename. Unfortunately I think in freak occations the other program can
>>> read and delete the file (running on a multicore processor system) during
>>> the rename operation. Can you suggest which errors I should be trying to
>>> catch?
>>>
>>
>> I'm not sure what errors to catch, but it's always possible to use a
>> general catchall (I'm not sure if this is particularly pythonic)
>>
>> try:
>> put your function here
>> except:
>> print 'oops! an error occurred!'
>>
>> Or do something besides print an error (such as write a message to a
>> logfile. If you include the time stamp and some other info that might be
>> helpful that may give you some more insight as to where the problem is, and
>> if it's something you can fix.)
>>
>
This might help:
http://www.python.org/doc/2.5.2/lib/module-logging.html

I don't really know though, it was just the first thing that came up when I
entered "python logging"
HTH,
Wayne
-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levihttp://
www.python.org/doc/2.5.2/lib/module-logging.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] finding numbers in range of of numbers

2008-10-20 Thread Srinivas Iyyer
dear group, 
a simple question that often challenges me. 

I have 

I have a list of list:

[[10,45],[14,23],[39,73],[92,135]]

I want to identify if any of the items in this list are in range of [5,100]

These numbers are large in original data, I will be using xrange for memory 
issues. 

 thank you. 
srini

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which exceptions should I be catching?

2008-10-20 Thread Wesley Brooks
>
> That's why you should write an error log ;)


The error log is a valid point. Is there a way to capture the error messages
that go the the terminal window or command prompt rather than all my print
statements? Can this be set up as a global thing for the whole application
rather than inside each thread?

try:
> put your function here
> except:
> print 'oops! an error occurred!'
>

I'll probably resort to this and have done in a couple of other occasions,
but thought it was generally frowned upon! I Guess I could do that and print
out anything caught by the exception into a log and go more specific at a
later date.

Cheers,

Wesley Brooks



> On Mon, Oct 20, 2008 at 3:30 PM, Wesley Brooks <[EMAIL PROTECTED]>wrote:
>
>> Unfortunately due to the nature of the program the error has normally
>> happened hours ago and the error message has disappeared from the buffer of
>> the command prompt.
>>
>
> That's why you should write an error log ;)
>
>
>>
>> This is the function:
>>
>> def CommandFileWriter(self, command):
>>   name1 = os.path.join(self.commandsdir, command + '.temp')
>>   name2 = os.path.join(self.commandsdir, command)
>>   comfile = open(name1, 'w')
>>   comfile.close()
>>   if not os.path.exists(name2):
>> os.rename(name1, name2)
>>   else:
>> os.remove(name1)
>>
>> This was the best way I could come up with doing the function. So the file
>> is written to the correct directory with a wrong name (so the other program
>> will ignore it) then it's name is changed to the correct name with
>> os.rename. Unfortunately I think in freak occations the other program can
>> read and delete the file (running on a multicore processor system) during
>> the rename operation. Can you suggest which errors I should be trying to
>> catch?
>>
>
> I'm not sure what errors to catch, but it's always possible to use a
> general catchall (I'm not sure if this is particularly pythonic)
>
> try:
> put your function here
> except:
> print 'oops! an error occurred!'
>
> Or do something besides print an error (such as write a message to a
> logfile. If you include the time stamp and some other info that might be
> helpful that may give you some more insight as to where the problem is, and
> if it's something you can fix.)
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Multiple lists from single list with nested lists

2008-10-20 Thread Sander Sweers
Hi, I am learning myself python and I need to create 2, or more but
let's use 2 as an example, lists from a list with nested lists.

For example the below,

['Test1', 'Text2', ['1', '2'], 'Text3']

Should result in,

[['Test1', 'Text2', '1', 'Text3'],
['Test1', 'Text2', '2', 'Text3']

I though of using a temp list and looping over the list twice, something like,

somelist = ['Test1', 'Text2', ['1', '2'], 'Text3']
templist = []
for x in range(len(somelist[2])):
templist.append([somelist[0], somelist[1], somelist[2][x], somelist[3]])

This works but to me looks ugly and would appreciate pointers and/or
someone pointing me to additional reading on this.

Much appreciated,
Sander
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] String and integer

2008-10-20 Thread Jens Frid
Hi,the code is:

def nr():
nr1 = input('Enter value: ')
print str(nr1).strip('nr0')

The user input is always on the form "nr08756" and i'd like to take out the
"nr0" and then print the result.
I can see that there is a problem with a variable looking like "pn0123"
because i get:
NameError: global name 'nr0123' is not defined.

What is the right way to do this?

Thanks!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which exceptions should I be catching?

2008-10-20 Thread W W
On Mon, Oct 20, 2008 at 3:30 PM, Wesley Brooks <[EMAIL PROTECTED]> wrote:

> Unfortunately due to the nature of the program the error has normally
> happened hours ago and the error message has disappeared from the buffer of
> the command prompt.
>

That's why you should write an error log ;)


>
> This is the function:
>
> def CommandFileWriter(self, command):
>   name1 = os.path.join(self.commandsdir, command + '.temp')
>   name2 = os.path.join(self.commandsdir, command)
>   comfile = open(name1, 'w')
>   comfile.close()
>   if not os.path.exists(name2):
> os.rename(name1, name2)
>   else:
> os.remove(name1)
>
> This was the best way I could come up with doing the function. So the file
> is written to the correct directory with a wrong name (so the other program
> will ignore it) then it's name is changed to the correct name with
> os.rename. Unfortunately I think in freak occations the other program can
> read and delete the file (running on a multicore processor system) during
> the rename operation. Can you suggest which errors I should be trying to
> catch?
>

I'm not sure what errors to catch, but it's always possible to use a general
catchall (I'm not sure if this is particularly pythonic)

try:
put your function here
except:
print 'oops! an error occurred!'

Or do something besides print an error (such as write a message to a
logfile. If you include the time stamp and some other info that might be
helpful that may give you some more insight as to where the problem is, and
if it's something you can fix.)

HTH,
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: how to see a number as two bytes

2008-10-20 Thread Steve Willoughby
> > high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.

My take would be something like

high, low = (num >> 8) & 0xff , num & 0xff

In case you want another option.  This is probably more
efficient since you're not raising to powers or taking the
modulus, although for all I know Python may optimize that
in these special cases anyway.  

Also, unless Python is doing more than I think it does
to watch out for your safety behind the scenes, this
is more safe against sign extension errors.

-- 
Steve Willoughby|  Using billion-dollar satellites
[EMAIL PROTECTED]   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Which exceptions should I be catching?

2008-10-20 Thread Wesley Brooks
Dear Users,

I've got a program that passes messages to another program in the form of
empty files, whereby the title of the file is the command. I've been
speaking to this board about this before about doing this in the quickest
possible way. Even with the code layed out as follows the code still breaks
once in a blue moon. Unfortunately due to the nature of the program the
error has normally happened hours ago and the error message has disappeared
from the buffer of the command prompt.

This is the function:

def CommandFileWriter(self, command):
  name1 = os.path.join(self.commandsdir, command + '.temp')
  name2 = os.path.join(self.commandsdir, command)
  comfile = open(name1, 'w')
  comfile.close()
  if not os.path.exists(name2):
os.rename(name1, name2)
  else:
os.remove(name1)

This was the best way I could come up with doing the function. So the file
is written to the correct directory with a wrong name (so the other program
will ignore it) then it's name is changed to the correct name with
os.rename. Unfortunately I think in freak occations the other program can
read and delete the file (running on a multicore processor system) during
the rename operation. Can you suggest which errors I should be trying to
catch? I guess the last four lines could also be caught by try except as
well. Although the program is currently running on windows XP I would like
any soloution to be cross platform for testing and future-proofing reasons.

Thanks in advance of any suggestions,

Wesley Brooks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can't start IDLE 2.6 on Mac

2008-10-20 Thread Alan Gauld


"Kent Johnson" <[EMAIL PROTECTED]> wrote


Unfortunately there is a problem with the Mac release of Python 2.6
and Tkinter (which IDLE uses) does not work correctly. The only fix 
at

this point is to use 2.5 or to build Python yourself.
http://bugs.python.org/issue4017

I hope there will be an official release that fixes this soon, it
seems like a serious problem to me.


Yep, this is why I almost never upgrade to new releases till they
have been out for several months!

But that looks like something that should have been caught in
earlier Release Candidates...

Alan G 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to clear the screen

2008-10-20 Thread Alan Gauld


"W W" <[EMAIL PROTECTED]> wrote 


if os.system('cls') == 0:
   pass
elif os.system('clear') == 0:
   pass
else:

 print '\n' * 80


That should take care of most of your OS' out there...


Why raise an error when you can just clear it by brute force?

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: how to see a number as two bytes

2008-10-20 Thread Luke Paireepinart
I'm not sure if those values are correct;  I can check later tonight,
but I'm doing some statechart diagrams for class right now.  They
sound reasonable but I can't be sure.

On Mon, Oct 20, 2008 at 11:20 AM, shawn bright <[EMAIL PROTECTED]> wrote:
> jeez, i screwed up, i ment num = 600, not 6
> thanks
>
> On Mon, Oct 20, 2008 at 11:16 AM, Luke Paireepinart
> <[EMAIL PROTECTED]> wrote:
>> No, I'm not sure what you mean.
>> Given this number
>>
>> 100101010101101011
>>
>> the operation will slice off bits on the left with the % 2**16 so that
>> we only have 16 bits,
>> 0101010101101011
>> then it will shift this value to the right so that we only have the
>> highest 8 bits
>> 01010101
>> that will be stored in high.
>> Then it will slice off the bits on the left with the 2**8 so that we
>> only have 8 bits left,
>> 01101011
>> and that is your low value.
>>
>> On Mon, Oct 20, 2008 at 11:04 AM, shawn bright <[EMAIL PROTECTED]> wrote:
>>> so using this, if num ==6, then i should get 2 and 88 ?
>>> thanks, just checking to make sure i get what you wrote.
>>> shawn
>>>
>>> On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
>>> <[EMAIL PROTECTED]> wrote:
 -- Forwarded message --
 From: Luke Paireepinart <[EMAIL PROTECTED]>
 Date: Mon, Oct 20, 2008 at 11:00 AM
 Subject: Re: [Tutor] how to see a number as two bytes
 To: shawn bright <[EMAIL PROTECTED]>


 high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.

 On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <[EMAIL PROTECTED]> wrote:
> hey there all,
> i have a script that needs to send a number as two bytes.
> how would i be able to see a number expressed as a hi byte and a lo byte?
>
> thanks
> shawn
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

>>>
>>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: how to see a number as two bytes

2008-10-20 Thread Luke Paireepinart
No, I'm not sure what you mean.
Given this number

100101010101101011

the operation will slice off bits on the left with the % 2**16 so that
we only have 16 bits,
0101010101101011
then it will shift this value to the right so that we only have the
highest 8 bits
01010101
that will be stored in high.
Then it will slice off the bits on the left with the 2**8 so that we
only have 8 bits left,
01101011
and that is your low value.

On Mon, Oct 20, 2008 at 11:04 AM, shawn bright <[EMAIL PROTECTED]> wrote:
> so using this, if num ==6, then i should get 2 and 88 ?
> thanks, just checking to make sure i get what you wrote.
> shawn
>
> On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
> <[EMAIL PROTECTED]> wrote:
>> -- Forwarded message --
>> From: Luke Paireepinart <[EMAIL PROTECTED]>
>> Date: Mon, Oct 20, 2008 at 11:00 AM
>> Subject: Re: [Tutor] how to see a number as two bytes
>> To: shawn bright <[EMAIL PROTECTED]>
>>
>>
>> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>>
>> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <[EMAIL PROTECTED]> wrote:
>>> hey there all,
>>> i have a script that needs to send a number as two bytes.
>>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>>
>>> thanks
>>> shawn
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: how to see a number as two bytes

2008-10-20 Thread shawn bright
thanks, Luke,
got me started anyway.
shawn

On Mon, Oct 20, 2008 at 11:23 AM, Luke Paireepinart
<[EMAIL PROTECTED]> wrote:
> I'm not sure if those values are correct;  I can check later tonight,
> but I'm doing some statechart diagrams for class right now.  They
> sound reasonable but I can't be sure.
>
> On Mon, Oct 20, 2008 at 11:20 AM, shawn bright <[EMAIL PROTECTED]> wrote:
>> jeez, i screwed up, i ment num = 600, not 6
>> thanks
>>
>> On Mon, Oct 20, 2008 at 11:16 AM, Luke Paireepinart
>> <[EMAIL PROTECTED]> wrote:
>>> No, I'm not sure what you mean.
>>> Given this number
>>>
>>> 100101010101101011
>>>
>>> the operation will slice off bits on the left with the % 2**16 so that
>>> we only have 16 bits,
>>> 0101010101101011
>>> then it will shift this value to the right so that we only have the
>>> highest 8 bits
>>> 01010101
>>> that will be stored in high.
>>> Then it will slice off the bits on the left with the 2**8 so that we
>>> only have 8 bits left,
>>> 01101011
>>> and that is your low value.
>>>
>>> On Mon, Oct 20, 2008 at 11:04 AM, shawn bright <[EMAIL PROTECTED]> wrote:
 so using this, if num ==6, then i should get 2 and 88 ?
 thanks, just checking to make sure i get what you wrote.
 shawn

 On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
 <[EMAIL PROTECTED]> wrote:
> -- Forwarded message --
> From: Luke Paireepinart <[EMAIL PROTECTED]>
> Date: Mon, Oct 20, 2008 at 11:00 AM
> Subject: Re: [Tutor] how to see a number as two bytes
> To: shawn bright <[EMAIL PROTECTED]>
>
>
> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>
> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <[EMAIL PROTECTED]> wrote:
>> hey there all,
>> i have a script that needs to send a number as two bytes.
>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>
>> thanks
>> shawn
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

>>>
>>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: how to see a number as two bytes

2008-10-20 Thread shawn bright
jeez, i screwed up, i ment num = 600, not 6
thanks

On Mon, Oct 20, 2008 at 11:16 AM, Luke Paireepinart
<[EMAIL PROTECTED]> wrote:
> No, I'm not sure what you mean.
> Given this number
>
> 100101010101101011
>
> the operation will slice off bits on the left with the % 2**16 so that
> we only have 16 bits,
> 0101010101101011
> then it will shift this value to the right so that we only have the
> highest 8 bits
> 01010101
> that will be stored in high.
> Then it will slice off the bits on the left with the 2**8 so that we
> only have 8 bits left,
> 01101011
> and that is your low value.
>
> On Mon, Oct 20, 2008 at 11:04 AM, shawn bright <[EMAIL PROTECTED]> wrote:
>> so using this, if num ==6, then i should get 2 and 88 ?
>> thanks, just checking to make sure i get what you wrote.
>> shawn
>>
>> On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
>> <[EMAIL PROTECTED]> wrote:
>>> -- Forwarded message --
>>> From: Luke Paireepinart <[EMAIL PROTECTED]>
>>> Date: Mon, Oct 20, 2008 at 11:00 AM
>>> Subject: Re: [Tutor] how to see a number as two bytes
>>> To: shawn bright <[EMAIL PROTECTED]>
>>>
>>>
>>> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>>>
>>> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <[EMAIL PROTECTED]> wrote:
 hey there all,
 i have a script that needs to send a number as two bytes.
 how would i be able to see a number expressed as a hi byte and a lo byte?

 thanks
 shawn
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: how to see a number as two bytes

2008-10-20 Thread shawn bright
so using this, if num ==6, then i should get 2 and 88 ?
thanks, just checking to make sure i get what you wrote.
shawn

On Mon, Oct 20, 2008 at 11:00 AM, Luke Paireepinart
<[EMAIL PROTECTED]> wrote:
> -- Forwarded message --
> From: Luke Paireepinart <[EMAIL PROTECTED]>
> Date: Mon, Oct 20, 2008 at 11:00 AM
> Subject: Re: [Tutor] how to see a number as two bytes
> To: shawn bright <[EMAIL PROTECTED]>
>
>
> high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.
>
> On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <[EMAIL PROTECTED]> wrote:
>> hey there all,
>> i have a script that needs to send a number as two bytes.
>> how would i be able to see a number expressed as a hi byte and a lo byte?
>>
>> thanks
>> shawn
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: how to see a number as two bytes

2008-10-20 Thread Luke Paireepinart
-- Forwarded message --
From: Luke Paireepinart <[EMAIL PROTECTED]>
Date: Mon, Oct 20, 2008 at 11:00 AM
Subject: Re: [Tutor] how to see a number as two bytes
To: shawn bright <[EMAIL PROTECTED]>


high, low = ((num % 2**16) >> 8, num % 2**8)  or something thereabouts.

On Mon, Oct 20, 2008 at 10:47 AM, shawn bright <[EMAIL PROTECTED]> wrote:
> hey there all,
> i have a script that needs to send a number as two bytes.
> how would i be able to see a number expressed as a hi byte and a lo byte?
>
> thanks
> shawn
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to see a number as two bytes

2008-10-20 Thread shawn bright
hey there all,
i have a script that needs to send a number as two bytes.
how would i be able to see a number expressed as a hi byte and a lo byte?

thanks
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing concatenated unicode strings

2008-10-20 Thread Tim Golden

Siim Märtmaa wrote:

i would like to do this


print u'\u30fa'

ヺ

with a method like this

b = "30fa"
uni = u'\u' + b + '\''

but it prints this

UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in
position 0-1: end of string in escape sequence

so how to concatenate properly to print the character ヺ

I want to do this to print the characters in a loop so that b would change




help (unichr)

Help on built-in function unichr in module __builtin__:

unichr(...)
   unichr(i) -> Unicode character

   Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10.






TJG
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Printing concatenated unicode strings

2008-10-20 Thread Siim Märtmaa
Hello

i would like to do this

>>> print u'\u30fa'
ヺ

with a method like this

b = "30fa"
uni = u'\u' + b + '\''

but it prints this

UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in
position 0-1: end of string in escape sequence

so how to concatenate properly to print the character ヺ

I want to do this to print the characters in a loop so that b would change
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to clear the screen

2008-10-20 Thread bob gailer

W W wrote:
On Mon, Oct 20, 2008 at 3:13 AM, Alan Gauld <[EMAIL PROTECTED] 
> wrote:


"Chris Fuller" <[EMAIL PROTECTED]
> wrote


want to clear the screen, printing the control sequence ESC[2J
is all you
need.

print chr(0x1b) + '[2J'


I don't know if this is the most graceful solution... but it seems to 
work:


import os

if os.system('cls') == 0:
pass
elif os.system('clear') == 0:
pass
else:
print 'No clear command available'


I'd prefer, for compactness and readability:

if not os.system('cls'):
 if not os.system('clear'):
  print 'No clear command available'


--
Bob Gailer
Chapel Hill NC 
919-636-4239


When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.


Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to clear the screen

2008-10-20 Thread W W
On Mon, Oct 20, 2008 at 3:13 AM, Alan Gauld <[EMAIL PROTECTED]>wrote:

> "Chris Fuller" <[EMAIL PROTECTED]> wrote
>
>  want to clear the screen, printing the control sequence ESC[2J is all you
>> need.
>>
>>  print chr(0x1b) + '[2J'
>

I don't know if this is the most graceful solution... but it seems to work:
import os

if os.system('cls') == 0:
pass
elif os.system('clear') == 0:
pass
else:
print 'No clear command available'

That should take care of most of your OS' out there...

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can't start IDLE 2.6 on Mac

2008-10-20 Thread Kent Johnson
On Sun, Oct 19, 2008 at 5:53 PM, Rob Stevenson <[EMAIL PROTECTED]> wrote:
> Hello,
>
> A slightly different question.  I use python on vista but recently bought a
> mac laptop running tiger so I could use garageband.
>
> I decided to put 2.6 on it but even though it installs fine, when I go to
> Applications / Python 2.6 and double click IDLE, nothing happens.

Unfortunately there is a problem with the Mac release of Python 2.6
and Tkinter (which IDLE uses) does not work correctly. The only fix at
this point is to use 2.5 or to build Python yourself.
http://bugs.python.org/issue4017

I hope there will be an official release that fixes this soon, it
seems like a serious problem to me.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] RUNNING A PROGRAM

2008-10-20 Thread Alan Gauld


"WM" <[EMAIL PROTECTED]> wrote


a = "Futzenburgerstein"
b = ( 7 + 2 ) / 3
c = b / 2
print a, b, c

The above text was copied from a window named
"??futz.py-C:\Python26\futz.py"  The ?? is two red
script characters which I cannot read.  When I go
'F5' or Run > Run Module I get kicked back into IDLE.
Shouldn't 'F5' get me a window with a, b & c printed
all in a row?


The output should appear in the shell window.

Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can't start IDLE 2.6 on Mac

2008-10-20 Thread Alan Gauld

"Rob Stevenson" <[EMAIL PROTECTED]> wrote

I decided to put 2.6 on it but even though it installs fine, when I 
go to

Applications / Python 2.6 and double click IDLE, nothing happens.


Does basic Python work?
If you open the Terminal application and type python at the prompt
does it come up? And is it the 2.6 uinstall or the pre-installed 
2.3(?)


Am I doing something wrong?  Unfortunately I'm very new to Macs so 
although
I'd be happy to investigate logs, registry etc on Windows, I don't 
know

where to begin on OSX.


I would strongly recommend a copy of the OS X Missing Manual book.
And then, if you intend doing any coding type work on Mac,  the
Mac OS X Hacks book from O'Reilly.

Which version of Python did you install? Was it MacPython or
ActiveState's Mac distro?

You might also need to start X windows running first if you don't
have the Cocoa version of Tk installed. I can't remember which
distros have which Tk...

IDLE on Mac is somewhat disappointing in my experience!

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to clear the screen

2008-10-20 Thread Alan Gauld

"Chris Fuller" <[EMAIL PROTECTED]> wrote

want to clear the screen, printing the control sequence ESC[2J is 
all you

need.


print chr(0x1b) + '[2J'


Only on *nix with a VT100 compatible terminal.
Doesn't work for vanilla DOS window or Tektronix mode
terminals, 3270 etc.

Thats why screen control is such a messy topic.

Alan G.



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to clear the screen

2008-10-20 Thread Alan Gauld


"Johnny" <[EMAIL PROTECTED]> wrote

In this program, it would be really neat if their was a way to clear 
the screen off.
I have inserrted comments as to where I'd like the screen to be 
cleared.


Such a simple question. Such a complex answer :-)

It all depends on what OS and terminal setup you are using.

If its windows you can do several things:
1) call the DOS CLS command using os.system() or similar
2) send the ANSI clear screen control code to the DOS window
  (if ANSI.SYS is installed)
3) send a lot of \ns to the screeen (simplest and most portable but 
slower)

4) Use a  3rd party screen handling module

If its Linux/MacOS/*nix:
You can use similar but slightly different tricks
1) call the Unix clear command
2) Send the clear screen control codes as determined by termcap
3) Send a lot of \n to screen
4) use the curses module to control the screen

Personally I'd go for 3 and write something like:

def cls(n=50): print "\n" * n

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a single .exe file without py2exe and pyinstaller

2008-10-20 Thread Alan Gauld


"Abah Joseph" <[EMAIL PROTECTED]> wrote

I have written a small application of about 40-45 lines which is 
about 4KB,
so I want to create a single .exe file from it, using py2exe it 
created
unnecessary files, that just increase the size of the program and 
also less

portable to me.


What kind of extra files?
One of Py2exe's main jobs is to strip out all the unnecessary
files and only bundle up those that are needed.

Have you tried installing the exe without the extra files? Does it 
still

work on a PC without Python already installed?

Py2exe usually does a pretty good job and has been around for
such a long time I'm surprised its producing any extras.

Curious,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor