Re: [Tutor] How to select particular lines from a text

2004-12-04 Thread R. Alan Monroe
> Name:
> City:
> 
> 

> Characterstics of this text:
> 1. This text is divided into blocks and every block
> start with 'Name'.  The number of lines after this
> identifier is random. 

[snip]

> 1. mark the identifier i need and select all the lines
> after that identifier until it hits a new line or
> another name identifier. 

A "while" loop was invented for those times in life where you don't
know in advance how many times you want to repeat something.

while line != "Name:":
  bigfile.readline()
#once this loop exits, you know you've found the first "Name:" line

while line != "Name:":
  bigfile.readline() #keep reading every line upto the NEXT one
  do stuff here

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


Re: [Tutor] Accuracy of time.sleep()

2004-12-04 Thread R. Alan Monroe
> IMO, instead of doing this you should use cron to make your script
> start at 08:05. It's probably cleaner.
> (and yes, there are some versions of cron for Windows -- I don't know 
> where they can be found, but I used one called nnCron Lite at my job 
> this summer)

There's the "at" commandline tool, and the Scheduled Tasks Control
Panel, both built in to Windows.

Alan

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


Re: [Tutor] Address book sort of

2004-12-06 Thread R. Alan Monroe
>   spaceMult=(highLength+minimumSpaces)-len(key)
>   outString=str(index)+". "+key+(spaceMult * " ") + item
>   print outString

> while len(display_name) < 25:
> display_name += '.'
> count += 1
> print count, display_name, d[item]

Rather than futzing with len()-based solutions, you might want to just
specify lengths in format strings:

>>> a='alan'
>>> print '*%10s*%-10s*' % (a,a)
*  alan*alan  *

Alan

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


Re: [Tutor] check_range

2004-12-14 Thread R. Alan Monroe
> def check_range(myrange):
> if range(myrange) != range(10,89):
> return "False"
> else:
> return "True"

For this to work out, the user's input would have to be a giant string
containing 10, 11, 12, 13, etc.

Unless I mistunderstood your requirements, what you're probably looking for is:

if myrange in range(10,90):  # "in" is the key word here
return True
else
return False

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


Re: [Tutor] Leading zero for hex numbers

2004-12-15 Thread R. Alan Monroe
> print "0x%0X" % 12345

> displays
> 0x3039

> instead of 0x03039



>>> "%05x" % (12345,)
'03039'

>>> "0x%05x" % (12345,)
'0x03039'

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


Re: [Tutor] can any one help

2010-01-31 Thread R. Alan Monroe

> 1 1.1 Write a Python program with a loop that prints out a sequence
> of numbers as follows:15 13 11...3 1 -1

Hint 1: Learn about FOR loops.

Hint 2: Learn about the RANGE command.

Hint 3: Show us some code you have written. Even if yours doesn't
work, we can probably spot WHY it doesn't work.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] query

2010-01-31 Thread R. Alan Monroe

> i just don wana index all the characters rather i wana double it too like 
>  ['d','a','v','i','d']
> would b 
>  ['d','dd','a','aa','v','vv','i','ii','d','dd']
> and then i wana replace all non 'd' characters with '.' a dot

> i know how replace a specific character, but i don know how to
> replace all characters other than a specific character

Hint 1: a FOR loop will help you count your way through lists one
at a time. Let the computer do the counting for you.

Hint 2: learn about IF statements to replace characters IF they're not
a d, for example.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Odds and even exercise

2010-03-27 Thread R. Alan Monroe
> odd = numbers[::2]

> I can't find a way to easily list the even numbers,

Hint: You can designate a start number before the first colon.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] conventions for establishing and saving default values for variables

2010-06-16 Thread R. Alan Monroe
> On Tue, Jun 15, 2010 at 2:27 PM, Pete O'Connell  
> wrote:
>> Hi I was wondering if anyone could give me some insight as to the best way
>> to get and save variables from a user the first time a script is opened. For
>> example if the script prompts something like "What is the path to the
>> folder?" and the result is held in a variable called thePath, what is the
>> best way to have that variable saved for all subsequent uses of the script
>> by the same user.
>> Pete

> In UNIX-likes, It would be a configuration file in their home
> directory, I suppose. Under windows, probably the registry. There's
> the _winreg and configparser modules.

Consider using the %USERPROFILE% environment variable rather than the
registry.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-18 Thread R. Alan Monroe
> That's the goal of the latest version of my script at
> . The best I've been able to do
> so far is a file with 800 million digits.

I don't think anyone else has suggested this: the numpy module can
generate random bytes and has a built-in tofile() method.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] continuous running of a method

2010-08-25 Thread R. Alan Monroe
> Any modern multi-tasking operating system will ensure than a while loop
> doesn't kill your computer's responsiveness. A decent operating system 
> will still remain responsive even at 100% CPU usage. Even Windows does 
> that!

Opinions vary. If you try this on a laptop, the end user will be quite
annoyed to see their battery drop to zero, their cooling fans go into
overdrive, and to receive first degree burns on their hands and/or
lap.

Busywaiting my cpu makes your program an instant candidate for
immediate deletion. Maybe that's just me :)

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Giving a name to a function and calling it, rather than calling the function directly

2010-09-04 Thread R. Alan Monroe
> if coinToss(1,2) == 1:
> heads += 1
> tossNo += 1
> else:
> tails += 1
> tossNo += 1

Looking good. You can hoist "tossNo += 1" out of each branch of your if
statement too, if you like, to make it even more streamlined (In
other words, execute it once, right after the coin flip, and before
the if-statement).

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list dll functions?

2010-09-14 Thread R. Alan Monroe
> the win32 lib, but is there any way to simply "examine" a loaded dll
> to see all of the functions and attributes it exposes for use? I would

http://www.dependencywalker.com/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] system()? popen2()? How to execute a command & save itsoutput?

2010-09-30 Thread R. Alan Monroe

>> I'm needing to transfer the following shell construct to Python, 
>> plus save
>> the output of execution:

>> FTP_SITE='ftp.somesite.com'
>> ftp -a  $FTP_SITE <> binary
>> prompt off
>> cd /some_dir
>> dir
>> bye
>> EOF

> Are you sure? It looks like you would be better writing a python
> program
> using the ftp module. Shells are intended to execute external programs
> but Python provides the tools to do the job directly from Python, with
> no need to start external programs in most cases.

NB: If you use the ftp module (which works great), be sure to open all
files in Binary mode. Voice of experience here.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] perl or python

2010-10-05 Thread R. Alan Monroe


> Is it better to learn  Perl or Python since i can manage only writing
> simple bash shell scripts.
> Please suggest/guide.

Do you already have both installed (seeing bash, I bet you're on some
version of Linux, so it's likely you do). You could try writing a very
simple "guess my number" game or some other very simple program in
both to see which you like best. Also, this might help you compare
them: http://www.99-bottles-of-beer.net/p.html

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Programs for Newbies?

2010-11-14 Thread R. Alan Monroe

> Any suggestions for a newbie to program while learning python?  I am new to
> programming and python.

Port one of the old games from
http://www.atariarchives.org/basicgames/ or similar antique books.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread R. Alan Monroe
> I've always disliked using "if not n % 2"  to test for even/odd ints
> because of its convoluted logic. But I ran some speed tests and found
> it was the way to go over "if n % 2 == 0".

Did you try bitwise-and with 1?

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "if n % 2 == 0" vs. "if not n % 2" compared for speed: aesthetics lose

2010-11-23 Thread R. Alan Monroe

>>> >> I've always disliked using "if not n % 2"  to test for even/odd ints
>>> >> because of its convoluted logic. But I ran some speed tests and found
>>> >> it was the way to go over "if n % 2 == 0".

>>> > Did you try bitwise-and with 1?

>>> What's that?

> 2 & 1
>> 0
> 3 & 1
>> 1

> So what's the connection with the tests I've run?

I'm wagering it will be faster than a modulo operation. Let us know
how it turns out :)

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple User Entry Verification

2009-03-14 Thread R. Alan Monroe

> while type(start)!=float:

Did you try quotes around the word "float"?

Alan

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


Re: [Tutor] Simple User Entry Verification

2009-03-14 Thread R. Alan Monroe
> Newbie here who can't figure out why this doesn't work:

> start = input("Please enter the starting number.\n>")
> print(type(start))
> while type(start)!=float:
> start = input("Sorry, that number was invalid.\nPlease enter the
starting number.\n>>")
> print(type(start))

Google to the rescue. Try this:
while not isinstance(start, float)


Alan

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


Re: [Tutor] for loop

2009-04-16 Thread R. Alan Monroe


 for letter in "python":
>  print "Current letter:", letter

 for chic in "python":
>  print "chic:", chic

When you write a for-in loop, you can use any variable name you feel
like using (letter, chic, mycoolvariable, x, etc.) It's that simple :)

Alan

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


Re: [Tutor] Reading from files problem

2009-04-19 Thread R. Alan Monroe

> gradesfile = open("grades.dat", "r
> for lines in gradesfile:
> [snip]
> That's what I have so far but I have a feeling I shouldn't use a for
> loop.

Actually a for loop seems like the right tool for this job, assuming
you really _do_ want to process every line in the file.

Alan

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


Re: [Tutor] sorting algorithim

2009-04-23 Thread R. Alan Monroe

> i know how to print for bubble sort in python, is there a way to
> print each pass in the sort so i can see what happens at each step? 
> thanks

A good first guess would be to try sticking "print list" in there in a
few different places.

Others will probably point out that "list" is a built-in keyword of
python so using it as a variable name may prevent you from using that
keyword.


Alan

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


Re: [Tutor] Monitoring a logfile

2009-12-01 Thread R. Alan Monroe
> Varnish has a dedicated (but not always) reliable logger service.  I'd
> like to monitor the logs - specifically I want to check that a known
> entry appears in there every minute (it should be there about 10 times
> a minute).

> What's going to be the best way to carry out this kind of check?  I
> had a look at SEC, but it looks horrifically complicated.

Ever used the seek() and tell() and readline() methods of a file
object? You could probably hack something together pretty quickly with
those.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] faster substring replacement

2009-12-15 Thread R. Alan Monroe
> Hi folks,

> I'm trying to do something like this:

 evildict= {'good' : 'bad' , 'love' : 'hate' , 'God': 'Satan'}

 def make_evil(text)
> ...        for a in evildict:
> ...              text=text.replace(a, evildict[a])
> ...              return text
>     

> This works fine, but it soon gets too slow as the size of text and dictionary 
> begin to grow.
> Can you guys suggest me a way to make it faster?

Would it help to do it in linear fashion? Reading the source text one
word at a time, doing a dict check for that word, then flushing that
word to output?

I'm wondering whether text.replace has to shove oodles of text to the
right in memory when you replace a shorter word with a longer word.
Someone else on the list may know.

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Generating Unique Permutations

2009-12-18 Thread R. Alan Monroe

> I'm looking for an efficient way to create all the unique, non-duplicated
> permutations of a list

This may or may not help:
http://code.activestate.com/recipes/190465/

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] computer basics

2009-12-29 Thread R. Alan Monroe
> I am learning Python slowly.  I would like to begin learning all
> about how computers work from the bottom up.  I have an
> understanding of binary code.  Where should I go from here; can you
> suggest continued reading, on line or off to continue my education?

This might be worth a look:
Digi-Comp I
http://www.mindsontoys.com/kits.htm

Alan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Is there a way to force update the screen in tkinter?

2005-01-10 Thread R. Alan Monroe
I don't have the code here at home, but today I tried my first
experiments in Tkinter. I set up a button that fired off a function to
resize a rectangle in a canvas, with a for loop. Only problem is that
the screen isn't repainted in all the steps of the for loop - only at
the very end, when the rectangle is at its final, largest size. Can I
make it repaint DURING the loop?

Alan

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


Re: [Tutor] carriage return on windows

2005-01-29 Thread R. Alan Monroe

> print "Percent completed:" + str(percent) + "\r"

Print forces a newline.
Try sys.stdout.write instead.

Alan

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


Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread R. Alan Monroe

> code to run it on a different platform. But most existing Java projects
> have platform-specific versions, if only to make the GUI (try to) look 
> native. You can spot a Java app from a hundred meters away.
> (then again, the same critic could be made of Python's and Perl's 
> "standard" GUI toolkits)

Amen. This drives me absolutely bonkers!

Alan

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


Re: [Tutor] Hex to Str - still an open issue

2005-02-10 Thread R. Alan Monroe
> I am not so clued up on the 'base 2' and 'base 8' stuff.
> Care to explain that a little?


Easy. Imagine the numerals 2,3,4,5,6,7,8,9 were never invented.
You'd start counting at 0.
Next would come 1.
Now you've maxed out your first column so you have to carry to the
next column, so next would come 10.

Alan

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


Re: Fwd: [Tutor] Create list of IPs

2005-02-20 Thread R. Alan Monroe
>> Liam Clarke wrote:

> [ snip ]

>> - increment an IP. This is the hardest part. 

> Why? An ip (V4) is just an 32bit integer :-)

Indeed. Some early versions of MacTCP for MacOS made you input the
address as a single large decimal number :^)

Alan

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


Re: [Tutor] threads

2005-02-25 Thread R. Alan Monroe
> Remember that I am generating cars even while the
> simulation is running, hence calculating this HCF at
> the beginning is not going to work. 
> Any comments?

This won't help you much in writing your program, but you might find
it interesting and vaguely similar to what you're doing:

www.simutrans.de

Alan

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


[Tutor] How to read unicode strings from a binary file and display them as plain ascii?

2005-02-28 Thread R. Alan Monroe
I started writing a program to parse the headers of truetype fonts to
examine their family info. But I can't manage to print out the strings
without the zero bytes in between each character (they display as a
black block labeled 'NUL' in Scite's output pane)

I tried:
 stuff = f.read(nlength)
 stuff = unicode(stuff, 'utf-8')
 print type(stuff), 'stuff', stuff.encode()

This prints:

  stuff [NUL]C[NUL]o[NUL]p[NUL]y[NUL]r[NUL]i[NUL]g[NUL]

Apparently I'm missing something simple, but I don't know what.

Alan

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


Re: [Tutor] Re: How to read unicode strings from a binary file and display them as plain ascii?

2005-03-01 Thread R. Alan Monroe
> R. Alan Monroe wrote:
>> I started writing a program to parse the headers of truetype fonts to
>> examine their family info. But I can't manage to print out the strings
>> without the zero bytes in between each character (they display as a
>> black block labeled 'NUL' in Scite's output pane)
>> 
>> I tried:
>>  stuff = f.read(nlength)
>>  stuff = unicode(stuff, 'utf-8')

>If there are embeded 0's in the string, it won't be utf8, it could be 
> utf16 or 32.
>Try:
> unicode(stuff, 'utf-16')
> or
> stuff.decode('utf-16')

>>  print type(stuff), 'stuff', stuff.encode()
>> This prints:
>> 
>>   stuff [NUL]C[NUL]o[NUL]p[NUL]y[NUL]r[NUL]i[NUL]g[NUL]

>I don't understand what you tried to accomplish here.

That's evidence of what I failed to accomplish. My expected results
was to print the word "Copyright" and whatever other strings are
present in the font, with no intervening NUL characters.


>Try the other encodings. It probably is utf-16.

Aha, after some trial and error I see that I'm running into an endian
problem. It's "\x00C" in the file, which needs to be swapped to
"C\x00". I cheated temporarily by just adding 1 to the file pointer
:^)

Alan#~ 11/30/1998  03:45 PM38,308 FUTURAB.TTF
#~ 11/30/1998  03:45 PM38,772 FUTURABI.TTF
#~ 12/10/1998  06:24 PM32,968 FUTURAK.TTF
#~ 12/30/1998  05:15 AM36,992 FUTURAL.TTF
#~ 12/15/1998  11:39 PM37,712 FUTURALI.TTF
#~ 01/05/1999  03:59 AM38,860 FUTURAXK.TTF

#~ The OpenType font with the Offset Table. If the font file contains only one 
font, the Offset Table will begin at byte 0 of the file. If the font file is a 
TrueType collection, the beginning point of the Offset Table for each font is 
indicated in the TTCHeader.

#~ Offset Table TypeNameDescription
#~ Fixedsfnt version0x0001 for version 1.0.
#~ USHORT   numTables   Number of tables.
#~ USHORT   searchRange (Maximum power of 2 <= numTables) x 16.
#~ USHORT   entrySelector   Log2(maximum power of 2 <= numTables).
#~ USHORT   rangeShift  NumTables x 16-searchRange.

import struct

def grabushort():
global f
data = f.read(2)
return int(struct.unpack('>H',data)[0])

def grabulong():
global f
data = f.read(4)
return int(struct.unpack('>L',data)[0])

f=open('c:/windows/fonts/futurak.ttf', 'rb')

version=f.read(4)

numtables = grabushort()
print numtables

f.read(6) #skip searchrange, entryselector, rangeshift

#~ Table Directory Type NameDescription
#~ ULONGtag 4 -byte identifier.
#~ ULONGcheckSumCheckSum for this table.
#~ ULONGoffset  Offset from beginning of TrueType font file.
#~ ULONGlength  Length of this table.

#for x in range(numtables):
for x in range(numtables):
tag=f.read(4)
checksum =grabulong()
offset = grabulong()
tlength = grabulong()
print 'tag', tag,  'offset', offset, 'tlength', tlength
if tag=='name':
nameoffset = offset
namelength = tlength

print 'nameoffset', nameoffset, 'namelength', namelength


#The Naming Table is organized as follows:
#~ Type NameDescription
#~ USHORT   format  Format selector (=0).
#~ USHORT   count   Number of name records.
#~ USHORT   stringOffsetOffset to start of string storage (from start 
of table).
#~ NameRecord   nameRecord[count]   The name records where count is the 
number of records.
#~ (Variable)   Storage for the actual string data.


#~ Each NameRecord looks like this:
#~ Type NameDescription
#~ USHORT   platformID  Platform ID.
#~ USHORT   encodingID  Platform-specific encoding ID.
#~ USHORT   languageID  Language ID.
#~ USHORT   nameID  Name ID.
#~ USHORT   length  String length (in bytes).
#~ USHORT   offset  String offset from start of storage area (in bytes).
print


f.seek(nameoffset)
format = grabushort()
count = grabushort()
stringoffset = grabushort()
print 'format', format, 'count', count, 'stringoffset', stringoffset

for x in range(count):
platformid = grabushort()
encodingid = grabushort()
languageid = grabushort()
nameid = grabushort()
nlength = grabushort()
noffset = grabushort()
print 'platformid', platformid, 'encodingid', encodingid, 'languageid', 
languageid, 'nameid', nameid, 'nlength', nlength, 'noffset', noffset
if platformid==3:# microsoft
bookmark = f.tell()
print 'bookmark', bookmark
f.seek(nameoffset+stringoffset+noffset+1)
stuff = f.read(nlength)
#stuff = unicode(stuff, 'utf-16')
stuff = stuff.decode( 'utf-16')
print type(stuff), 'stuff', stuff
f.seek(bookmark)


f.close()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to read unicode strings from a binary file and display them as plain ascii?

2005-03-01 Thread R. Alan Monroe
> R. Alan Monroe wrote:
>> I started writing a program to parse the headers of truetype fonts to
>> examine their family info. But I can't manage to print out the strings
>> without the zero bytes in between each character (they display as a
>> black block labeled 'NUL' in Scite's output pane)
>> 
>> I tried:
>>  stuff = f.read(nlength)
>>  stuff = unicode(stuff, 'utf-8')

> I think you need 'utf-16be', not 'utf-8'. See this page if you don't know the 
> difference:

Outstanding! Batteries included, indeed.

Alan

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


Re: [Tutor] Re: How to read unicode strings from a binary file and display them as plain ascii?

2005-03-03 Thread R. Alan Monroe
 print type(stuff), 'stuff', stuff.encode()
This prints:

  stuff [NUL]C[NUL]o[NUL]p[NUL]y[NUL]r[NUL]i[NUL]g[NUL]
>> 
>> 
>>>   I don't understand what you tried to accomplish here.
>> 
>> 
>> That's evidence of what I failed to accomplish. My expected results
>> was to print the word "Copyright" and whatever other strings are
>> present in the font, with no intervening NUL characters.

>Oh but why print type(stuff)
To make sure it really came back as , as opposed to
.

>  or 'stuff'?
Personal tradition :^)

The outcome of the project was this: Firefox would not display bold
text correctly when I selected "Futura Lt BT" as my font (it would
display a stretched version of the Light font, even though I also had
"Futura Bold BT" in my fonts folder).

After some googling, I figured out that (if I understand it right)
Windows groups plain fonts and bold fonts together based on their
internal family name, which turned out to be different between the two
fonts.

futural.ttf
Font Family name : Futura Lt BT
Font Subfamily name : Light

futurab.ttf
Font Family name : Futura Md BT
Font Subfamily name : Bold

So as best I can tell, the d*mb*asses that made Word Perfect Office
2002 (pre-loaded on my computer when I bought it) failed to give me
the entire font family.

Alan

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


[Tutor] Anyone know of a window utility to reverse engineer unknown binary graphic file format?

2005-03-05 Thread R. Alan Monroe
I know it's a long shot but...

I have some graphics files from an old DOS game that I want to convert to
a normal .png or whatever. Anyone know of a program that can load
binary data and view it multiple different ways? Like treating the raw
data as 1 bit, 4 bit, 8 bit, planar, linear, adjust the pitch and
offset, etc. in some kind of GUI until you get a recognizable image?

The game reads its graphic files in 512 byte increments at runtime,
judging by sysinterals filemon. This gave me a little hope that the
graphics are uncompressed even multiples of 512 bytes each.

I used python to read the 1st 512 bytes of the file and output it to
another file, for experimentation. I wrote a script to read that in
and output the high 4 bits as a byte, and the low 4 bits as a
subsequent byte, but that image didn't really look like anything
recognizable, loading it as raw into Photoshop.

Alan

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


Re: [Tutor] (no subject)

2005-03-06 Thread R. Alan Monroe
>> Is the tutor list mirrored on usenet such as google groups? I've
>> searched and not found it.

> Nope, the archives are available but there is no usenet mirroe.

What about this:
http://dir.gmane.org/gmane.comp.python.tutor

Alan

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


[Tutor] Can you get python to force a number to remain 32 bit instead of autoconverting to type 'long'?

2005-03-07 Thread R. Alan Monroe
I tried to convert this pseudocode

function IntNoise(32-bit integer: x)
x = (x<<13) ^ x;
return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fff) / 
1073741824.0);
end IntNoise function

from this website
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

to python. But it seems to rely on wraparound within the 32 bit int.
Can you duplicate this behavior in python?

Alan

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


Re: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread R. Alan Monroe
> I have a script that converts data relating to my work.

> It works great on my Linux system but some of my colleagues run windows. 
> I am attempting to convert the file paths to windows but am having no luck.

> I need to access 'memo.txt' in 'my documents' on windows & am struggling.
> I have tried just about every combination of \ and / and \\ and // but 
> to no avail.
> I need something like ...

> C:\My Documents\memo.txt

You'll have to come up with some windows-specific trick to find out
the current user, because "my documents" is actually in
c:\documents and settings\currentusername\my documents\

Try getting it from the HOMEPATH environment variable.

import os
print os.environ['HOMEPATH']


Alan

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


Re: [Tutor] help

2005-03-13 Thread R. Alan Monroe

> ok i have learned that on the python shell or new window you can type 
in..print "hello world"...and the output is ..'hello world'.. or you 
can 
> put in anything realy and it say it back to you.is this a program or what

Yep, that's a program. Just an ultra, ultra-simple one.


> program and what i need to know to write them and if this is a program teach 
> me
> how to write better programs

Have you learnt the "if" statement yet? If not, that's the next thing
you want to learn. Tell us if you get stuck.


Alan

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


Re: [Tutor] I need some guidance

2005-03-23 Thread R. Alan Monroe
> My first question is do i need to really understand everything first time I
> come across or does it get easier if you kind of move along and get back to 
> it later?

My personal experience is that anything makes more sense when you come
back to it later, so yes :^)


> Third question: Does anybody know if it is possible to get involved in this
> field in a non-lucrative kind of way in order to learn faster and of course 
> to apply this science in a real world.

There are programming contests from time to time, on various web
sites. You can probably find loads of them on Google.

Alan

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


Re: [Tutor] comparison function/built-in needed

2005-04-06 Thread R. Alan Monroe

> I am attempting to compare the items in two lists across two criteria - 
> membership and position. For example:

> list_a = [ 0, 4, 3, 6, 8 ]
> list_b = [ 1, 8, 4, 6, 2 ]

> Membership = There are 3 items that are common to both lists, that is 3 
> items in list_a have membership in list_b (viz: 4, 6, 8);
> Position = There is 1 item in list_a that is also in the same position 
> in both lists (viz: 6).

Not sure if this will help, but take a look at Levenshtein Distance:
http://www.merriampark.com/ld.htm

Alan

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


Re: [Tutor] Multithreading and Daemon Program

2005-04-13 Thread R. Alan Monroe
> An IP Camera will send images to the server via ftp to a folder.
> Each user has a folder and I want to know how I can make my app to
> check the folders ('cause there is going to be many cameras sending
> files and that means that the app will have to check every folder)
> every x seconds?

> Will I have to make one process for every user or one for each
> user??

I bet you could get it to work both ways (seperate threads for each
folder, or a single thread that checks all the folders one at at time).

Once you detect that there are pictures in someone's folder, what do
you do with them?

Also I posted this short message about my first experiences with
threading about a year ago, in case it helps:

> - def a function that you want to get executed in a subthread
> - create a new thread, feed it the name of the function above
> - start the new thread
> 
> at this point, you need not execute any further statements in your
> program. The main program will wait indefinitely for the child thread
> to complete. Once it's done, the main program will exit too. It's kind
> of neat to watch, the first time you try it.

Alan

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


Re: [Tutor] Re: Recursion....what are the best situations to use it?

2005-04-14 Thread R. Alan Monroe

> I know that the Eight Queens puzzle is a good recursion candidate,
> but I don't understand why as yet. I'm still on simple recursion,
> and am just beginning to understand backtracking in a simple
> example, like adding numbers in an array.

If you make a typo when typing an email, do you delete the whole
message and start over? Probably not :^)

With recursion, you can just back up a few steps to the parts that were
known to be working and carry on again from there.

Alan

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


Re: [Tutor] high score lists

2005-04-14 Thread R. Alan Monroe
> Anyone have some good beginning ideas/references to creating a high
> score list and storing scores in a simple python game? (if there's
> something in the pygames module, or a simpler python way).  I'm
> mod'ing a space invaders-type game and would like to add a high score
> list :)

Quick and dirty approach: make a list of tuples
[ (4, 'John Doe'),
  (3, 'Steve Austin') ]

You can append new ones to the end of the list, sort it, reverse it,
etc.

Alan

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


Re: [Tutor] Re: newbie intro to pickle

2005-04-16 Thread R. Alan Monroe

> Now my question is how do you keep people from just loading
> the high score file with whatever scores they want?

> This is not to disparage a simple (and probably very useful)
> high score file. It is just something that I have been thinking
> about doing myself for quite a while, but I can never quite get
> a grasp on how I would go about it.

This is a recurring discussion in a lot of usenet newsgroups. The
prevailing wisdom is: don't bother. Any way you come up with to keep
it secret can be defeated. Period.

Alan

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


[Tutor] Has anyone ever tried to convert the textual output of the dis module to another language

2005-04-16 Thread R. Alan Monroe
Just curious. Googling for 'python "dis module" convert "another
language" ' only got two hits. So maybe no one is trying it? I was
just daydreaming about a native python compiler, and wondered how
feasible it would be.

Alan

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


Re: [Tutor] Has anyone ever tried to convert the textual output of thedis module to another language

2005-04-16 Thread R. Alan Monroe
>> Just curious. Googling for 'python "dis module" convert "another
>> language" ' only got two hits. So maybe no one is trying it? I was
>> just daydreaming about a native python compiler, and wondered how
>> feasible it would be.

> I hope that your true google search string doesn't contain the two single
> quote on the outside...

Nope. That was just to set it off from the rest of the sentence in the
email.

> So basically any website that contains 'dis module', which stands for what
> by that way?

It's python's included disassembler for its own virtual machine. It's
interesting to play around with. Try:

import dis
dis.dis(name of some function you def'd in your program)


Alan

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


Re: [Tutor] Has anyone ever tried to convert the textual output of the dis module to another language

2005-04-17 Thread R. Alan Monroe
> R. Alan Monroe wrote:
>> Just curious. Googling for 'python "dis module" convert "another
>> language" ' only got two hits. So maybe no one is trying it? I was
>> just daydreaming about a native python compiler, and wondered how
>> feasible it would be.
>> 

> There is already a python -> exe converter. Comes up on the list now and 
> then. What would your idea change?

The main things about it that would make it appealing to me:

#1 - MUCH MUCH MUCH smaller exes. Speed is not an issue to me, but
filesize is. Have you ever compiled "Hello world" in a new language,
and found that the exe was 100K+, when it really only needs to be less
than 1K? And py2exe... I am not averse to using it, but 800 - 1000K+
exes, well, it's just my pet peeve.

#2 - Love of classic hacking wizardry. :^)

Alan

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


Re: [Tutor] Has anyone ever tried to convert the textual output of the dis module to another language

2005-04-18 Thread R. Alan Monroe
>> > Just curious. Googling for 'python "dis module" convert "another
>> > language" ' only got two hits. So maybe no one is trying it? I was
>> > just daydreaming about a native python compiler, and wondered how
>> > feasible it would be.
>>
>> You might be interested in Pyrex and Psyco:
>> http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/
>> http://psyco.sourceforge.net/


> PyPy might also be very useful:
> http://codespeak.net/pypy/

Cool. I also found this while googling around:

http://www.foretec.com/python/workshops/1998-11/proceedings/papers/aycock-211/aycock211.html

Alan

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


Re: [Tutor] Installation Routines (Joseph Quigley)

2005-04-18 Thread R. Alan Monroe
> He told me that it
> was for writing an installation program for Windows and that he considered 
> python and Tkinter as an option.
> I know there are installers written in python for Linux. I suppose they are 
> easier to write, than one for Windows?

> Now, I'm still new, and can't do GUI yet, but I was wondering how hard 
> would it be to write a simple installer for windows? None of that fancy INI 
> and registry crapp, just a very simple file copier to, oh lets say, My 
> Documents?

> This isn't a waste of your or my time is it?

It's pefectly doable, but with the existence of Innosetup and NSIS,
personally I wouldn't really feel like it was worth it. Just my
opinion, though.

Alan

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


Re: [Tutor] TKinter and things over Linux

2005-04-20 Thread R. Alan Monroe

> apt-get and yum are available for Redhat style releases.  They will
> download and install packages and figure out the dependency issues.
> (yum is written in Python so this is slightly on topic.)

Gentoo's "emerge" system is also written in Python.

Alan

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


Re: [Tutor] Python Challenge - Riddle 2

2005-05-09 Thread R. Alan Monroe
> Hi John, took me awhile to solve this one too, it's quite good, teaches you 
> about a part of Python that you wouldn't normally use.

> Do you want hints or spoilers?

> I've give hints for now, search the Python docus for 'trans', check the 
> string methods.

You can also do it with a convoluted list comprehension - that's what
I did.

Alan

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


Re: [Tutor] Python Challenge - Riddle 2

2005-05-09 Thread R. Alan Monroe

> Am I looking for something like this - 

> XXXjXXX? or something like XjXX or XXjX? I've also looked for - 

Take the challenge's hint a little more literally, it's quite
specific. This one had me stumped for a little while until I realized
my mistake.

Alan

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


Re: [Tutor] zip question

2005-05-10 Thread R. Alan Monroe
> I need some pointers to solve number 7. For what I can see on that picture
> the only hint is the gray line inside the .png drawing, but what can I do 
> with it?
> Just tell me where to start and I will try to get from there

Have you ever learnt about graphics and pixel colors? You know, like
red, green and blue combining to make colors and stuff?

Alan

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


Re: [Tutor] Riddle 8

2005-05-11 Thread R. Alan Monroe

> Do I really have to connect the dots
> And how can I do that using the obviuos module?

I used pygame to do it. Also you could probably do it with Image, to a
file (and then view that file with your favorite picture viewer).

Alan

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


Re: [Tutor] Running RPG game again.

2005-05-21 Thread R. Alan Monroe
> I'm trying to make the RPG game to be able to run again.

> But, when I type "run", nothing happens.

It's because your continue statement on line 45 loops around to line
19 (I double checked in the debugger).

Then it checks if the monster is still alive (AGAIN) on line 20, but
the monster is already dead, so the whole inner while loop is skipped
and the program will jump straight to line 43 again.

You might want to change your outermost while loop to something like
this:

iloveplaying=1
while iloveplaying:
(move all the variable setup inside the main while loop
 that way the monster is reborn every time you play)

while (mob>0):
(do all the fighting stuff here as normal)

run = raw_input("\nrun or exit ")
if run != "run":
iloveplaying=0



Alan

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


Re: [Tutor] python/ pygame on XP: window not responding

2005-06-29 Thread R. Alan Monroe

> I am a new python/ pygame user. In attempting the simple 
> command pygame.display.set_mode((640,480))
> The newly created window is not responding. I am using these programs with
> the Windows XP operating system. Can you provide any suggestions or help
> with this issue??

Does the chimp.py example from pygame run on your box?

I'm betting you're just not processing the event queue, so the OS
thinks the app is hung.

Alan

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


Re: [Tutor] [pygame] Fwd: A more Pythonic way to do this

2005-07-05 Thread R. Alan Monroe
> should be returning each to its original starting position. Since I
> create initialx/initialy for each enemy when the screen full of
> enemies is drawn (and I know I do create a new initialx/initialy for
> each one - because I had it print the initialx, initialy when the
> screen was drawn and I get 40 sets of values printed for the 40
> enemies on the screen), wouldnt each instance of the Enemy class store
> its own initialx initialy so that when I called
> each.rect.centerx = Enemy.initialx
> each.rect.centery = Enemy.initialy
> .. it would return each to its own starting position?

> Right now, it seems to be printing them all right on top of the other,
> in one enemy position.  At first I thought I was redrawing only one
> enemy, but I shot it, and there seems to be another underneath it. A
> lot of others, actually.  So I can't even see if it is drawing just
> the ones that havent been killed yet or a whole new batch.  And,
> obviously, it's not relocating them correctly :P

Did you inadvertently set the initialx & initialy on a class-wide
basis (within the class's definition), when you meant to set it on a
per-instance basis (within each enemy one at a time)?

Alan

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


Re: [Tutor] OT python Licences

2005-07-14 Thread R. Alan Monroe
> As far as I know, all GTK+ 2.x
> applications under Windows have a native look.  I don't know my self as
> I don't have Windows.

My personal experience is that GTK apps (Ones I've used like GAIM,
Inkscape, Ethereal) on Windows stick out like a sore thumb, GUI-wise.
They tend not to use the same font, or font size as normal apps. They
are typically slower at painting their menus to the screen. They also
have other oddities such as tooltips that tend to "stick" on the
screen, and they don't refresh their windows when viewed via VNC.

Alan

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


Re: [Tutor] Performance difference, ``in'' vs ``has_key()''

2005-07-17 Thread R. Alan Monroe
> Is there any significant performance difference between the
> tests, ``key in dictionary'' and ``dictionary.has_key(key)''?
> I would prefer using the ``key in'' because it's a bit easier to
> type, and can also be used with lists in addition to dictionaries.

Dunno about speed, but they do disassemble slightly differently:


>>> import dis
>>> a={1:2, 3:4}
>>> def x():
... if 3 in a:
... print "3 in"
...
>>> def y():
... if a.has_key(3):
... print "3 has"
...
>>> dis.dis(x)
  2   0 LOAD_CONST   1 (3)
  3 LOAD_GLOBAL  0 (a)
  6 COMPARE_OP   6 (in)
  9 JUMP_IF_FALSE9 (to 21)
 12 POP_TOP

  3  13 LOAD_CONST   2 ('3 in')
 16 PRINT_ITEM
 17 PRINT_NEWLINE
 18 JUMP_FORWARD 1 (to 22)
>>   21 POP_TOP
>>   22 LOAD_CONST   0 (None)
 25 RETURN_VALUE
>>> dis.dis(y)
  2   0 LOAD_GLOBAL  0 (a)
  3 LOAD_ATTR1 (has_key)
  6 LOAD_CONST   1 (3)
  9 CALL_FUNCTION1
 12 JUMP_IF_FALSE9 (to 24)
 15 POP_TOP

  3  16 LOAD_CONST   2 ('3 has')
 19 PRINT_ITEM
 20 PRINT_NEWLINE
 21 JUMP_FORWARD 1 (to 25)
>>   24 POP_TOP
>>   25 LOAD_CONST   0 (None)
 28 RETURN_VALUE


Alan

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


Re: [Tutor] Web Browser in Python

2005-08-03 Thread R. Alan Monroe
>> I need to program a web browser in python.I dont have any idea of how to
>> start, what i do have is time and willingness to learn.Could anyone direct
>> me to some suitable reference? 
>> Shitiz
>> 

> How about Grail http://grail.sourceforge.net/ ?

Looks neat, but it doesn't run on my box:

C:\net\grail-0.6>grail.py
C:\net\grail-0.6\grailbase\app.py:6: DeprecationWarning: the regex module is 
deprecated; please use the re module
  import regex
C:\Python23\lib\regsub.py:15: DeprecationWarning: the regsub module is 
deprecated; please use re.sub()
  DeprecationWarning)
Traceback (most recent call last):
  File "C:\net\grail-0.6\grail.py", line 499, in ?
main()
  File "C:\net\grail-0.6\grail.py", line 108, in main
app = Application(prefs=prefs, display=display)
  File "C:\net\grail-0.6\grail.py", line 248, in __init__
self.stylesheet = Stylesheet.Stylesheet(self.prefs)
  File "C:\net\grail-0.6\Stylesheet.py", line 21, in __init__
self.load()
  File "C:\net\grail-0.6\Stylesheet.py", line 45, in load
massaged.append((g, c), v % fparms_dict)
TypeError: append() takes exactly one argument (2 given)

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


Re: [Tutor] XMMS song search

2005-08-07 Thread R. Alan Monroe

> songsearch = raw_input(Enter song name: ")
> f = file(/home/joe/.xmms/xmms.pls)

Don't forget your quotation marks around the filename.


> f.find(songsearch)

You _find_ stuff in strings, not in the file itself. Read each line of
the file one at a time, because each line will be a string.


for thisline in f:
if thisline.find(songsearch) > 0:
   print thisline


#Also at the end of the program don't forget to close what you opened
f.close()



Alan

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


Re: [Tutor] screen scraping web-based email

2007-04-18 Thread R. Alan Monroe

> I'm starting graduate school (econ!) in the Fall; the school I'll be
> attending uses Lotus for email

You can drive the fat client via COM if you install the Win32
extensions for python.

> (I know I could do it with a torturous combination of applescript and

Except judging by this, you're on a MAC... so maybe not. Still,
working WITH the app (using its APIs) is bound to better than working
AGAINST it (screen scraping).

Alan

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


Re: [Tutor] trying to figure out what this means

2007-05-07 Thread R. Alan Monroe
> when you are doing print these two characters keep showing up in this book
> "%s" %

> What do they do?

"Fill in the blank"

Kind of like generic paper forms where they have a blank underline for
you to fill in your information.

Give it a variable name, and it will fill in the "blank" (the %s) with
the variable's value.

Alan

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


Re: [Tutor] Sum of Scores

2007-07-26 Thread R. Alan Monroe

> I want to be able to calculate in the program,.. the total score,..
> either at each successive score,... or when they finally get out.
> Not sure how to do that at this point.

You're on the right track. You need an additional variable to hold the
running total.

Alan

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


Re: [Tutor] LosingtheexpressivenessofC'sfor-statement?/RESENDwithexample

2007-08-11 Thread R. Alan Monroe

> "Noufal Ibrahim" <[EMAIL PROTECTED]> wrote

>> I think such treatment of the various python constructs should be
>> reserved for documents like say, "Python for C programmers"(

> Actually that's not a bad idea, except I'm not sure such convertion
> courses exist?

> But it would be useful to have a set of concise crib sheets for
> the most common conversion languages, say:

> Java, Perl, C/C++, Visual Basic and Unix shell
> (and maybe Mathematica and Lisp).

> Now those would be sensible places to document how to 'translate'
> common language idioms into Python and point out the Pythonic
> alternative idioms.

> Does anyone know of any good starting points? If there were a standard
> format it might be quite a nice "cottage industry" section of the 
> python
> web site that could grow as people added new guides... In fact it 
> could
> be a Topic Guide section to itself...


http://99-bottles-of-beer.net/

:)

Alan

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


[Tutor] A fun puzzle

2007-08-22 Thread R. Alan Monroe
I wrote a lame, but working script to solve this in a few minutes. A
fun puzzle.

http://weblogs.asp.net/jgalloway/archive/2006/11/08/Code-Puzzle-_2300_1-_2D00_-What-numbers-under-one-million-are-divisible-by-their-reverse_3F00_.aspx


Alan

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


Re: [Tutor] Logging with proper format

2007-10-07 Thread R. Alan Monroe

> logger.info("Checked %s records in %s seconds, yielding an average of 
> \
> %s seconds per record." % (len(self.data), duration, avgquery) )
 ^

Remove these spaces. It makes the source code look weird, but the
output will be correct.

Alan

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


[Tutor] How to get python to differentiate between CR, LF, and CRLF in a string (not a file)?

2007-12-14 Thread R. Alan Monroe
Is is possible to get python to differentiate between CR, LF, and CRLF
in a string (not a file)? This is a triple quoted string I've pasted
into the source (putting r to indicate raw string made no difference).
It contains a mixture of CR, LF and CRLF (I can see this by enabling
visible End of Line markers in Scite). I need to distingush between
them.

Whenever I iterate over the string, it's automagically converting all
variants to an ascii 10.

for x in entry:
print repr(x), ord(x)

...
'S' 83
'c' 99
'h' 104
'e' 101
'd' 100
'u' 117
'l' 108
'e' 101
'd' 100
'\n' 10  <--- this should be a 13 followed by a 10
...


Alan

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


Re: [Tutor] Program Specification Request

2008-01-16 Thread R. Alan Monroe

>I would like to learn and teach my 2 girls a mini
> database GUI program in Python and 
>They are Girl Scouts (and advanced MS & HS
> students)

http://davidbau.com/archives/2005/07/29/haaarg_world.html

Alan

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


Re: [Tutor] how to parse a multiple character words from plaintext

2008-02-23 Thread R. Alan Monroe
> I am looking to parse a plaintext from a document. However, I am
> confused about the actual methodology of it. This is because some of
> the words will be multiple digits or characters. However, I don't
> know the length of the words before the parse. Is there a way to
> somehow have open() grab something until it sees a /t or ' '?

If your file format is not too fancy, split() may be all you need.

Alan

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


Re: [Tutor] What can I do with this code?

2005-08-09 Thread R. Alan Monroe
> print random.choice(cool)


> What can I do with it, other than let it be a fun example of coding?

Make a Magic 8 ball! :^)

Alan

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


Re: [Tutor] How can I make this run right?

2005-08-15 Thread R. Alan Monroe
> The following code is supposed to take in a number, and print number!:
> n = int(raw_input("Number: "))
> x = n-1
> while 1:
> t = n*x
> while x > 1:
> x -= 1
> else:
> break
> print t

> Why isn't it working, and how can I make it print out the correct output?

One thing you might find handy is IDLE's debugger (if you use IDLE).
Turn it on under Debug / Debugger. Make sure the "Source" checkbox is
checked. Then hit the step button to run your program in "slow motion"
so you can see everything it does one step at a time.

(You might have to temporarily click the output window to the front
when the raw_input wants you to type a number)

Alan

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


Re: [Tutor] Searching Sorted Lists

2005-08-21 Thread R. Alan Monroe
> [EMAIL PROTECTED] wrote:
>> Hi, Can someone tell me if there is a bulit in Binary search function for
>> python lists ?
>> 
>> I am currently building lists and sorting them with a comparison function.
>> The only list search function I know is List.Index(X), which is pretty
>> inefficient I reckon, especially hen the lists are likely to contain 100's
>> or 100's of members.

> Hundreds or thousands of entries are pretty much nothing in computer 
> terms. Unless you have measured that it's a bottleneck in your 
> application, I wouldn't bother finding an alternative to index().

>  > Is there a search function that uses a compariosn function / binary 
> chop ?
>  > or will I have to implement my own ?

> It's quite easy to code it yourself if necessary. The Wikipedia has a 
> nice article on it, including sample code which looks very much like 
> Python: http://en.wikipedia.org/wiki/Binary_search

Can you use the built-in heapq module?

Alan

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


Re: [Tutor] Network Programming Information and terminology

2005-08-22 Thread R. Alan Monroe
> Hello. It's me again.  Thanks for all the help with
> the Python Networking Resources, but does anyone know
> what I'll need to know to write a paper on Network
> Programming and Python.  Like terminology and all
> that.  Maybe I'll have a section on socketets, TCP,
> Clients (half of the stuff I don't even know what it
> means).  So, does anyone know any good websites with
> Network Programming information.  Thanks!

http://www.itprc.com/tcpipfaq/default.htm

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


Re: [Tutor] running scripts with windows

2005-09-15 Thread R. Alan Monroe
>> Cygwin (http://www.cygwin.com/)  It gives you a bash shell in 
>> Windows.

> Actually it gives you a whole Unix environment including X Windows
> and over 500 unix command line tools plus GNU C, sendmail, etc etc...

Watch out, because cygwin-native python can conflict with win32
python, if they're both in your path. Buddy of mine had various .py
files not work because of this.

Alan

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


Re: [Tutor] Maths: getting degrees from radians (or am I wrong?)

2005-09-20 Thread R. Alan Monroe
> Bernard Lebel wrote:

>  >>> import math
>  >>> math.acos(-0.0634)
> 1.6342388771557625
>  >>> math.degrees(_)  <--- in all my time on tutor
 I have never noticed
 this underscore trick
 before
> 93.634990377223801

That's quite handy.

Alan

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


Re: [Tutor] Binary 2 text & text 2 binary

2005-09-23 Thread R. Alan Monroe

> I thought lists would be the best but I really don't know how to use
> them

They're easy. Just put stuff in square brackets with commas between.

mycoollist = [1,5,9,3,6,9,2,6]
mystringlist = ['a', 'u', 'e', 'b', 'd', 'h', 'q', 't']

Can you predict what this code will do?

print mycoollist[0]



Alan

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


Re: [Tutor] Sum of List Elements

2005-09-24 Thread R. Alan Monroe
> Hi All,

> I have spent an embarrassingly large amount of time trying to solve what on
> its face seems like a simple problem.

> I have a list of intergers, and I want to assign the sum of the intergers in
> the list to a variable. There are only intergers in the list.

> The best I have been able to do so far is to write a function that adds
> list[0] and list[1], then list[1] and list [2], etc. Of course, this isn't
> what I want.

> I'd like to be able to sum a list of any size without having to type
> list[0]+list[1]

total=0
for x in list:
total += x

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


Re: [Tutor] printing an acronym

2005-09-24 Thread R. Alan Monroe
> Hello

> How could I get the following to print out an acronym for each phrase
> entered such as if I entered random access memory it word print out RAM?

> import string

> def main():


> phrase = (raw_input("Please enter a phrase:"))

> acr1 = string.split(phrase)


> acr2 = string.capwords(phrase)


> acr3 = acr2[0]

> print"",acr3

> main()

What does it currently print?

The typical way would be to use a for loop on acr1.

Alan

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


Re: [Tutor] 'print' without newline or space appended

2005-09-25 Thread R. Alan Monroe
> Hello,

> This statement:
>   for c in 'hello': print c
> will generate following output:
>   h
>   e
>   l
>   l
>   o
> and by adding comma at the end of the print statement:
>   for c in 'hello': print c,
> we get this output:
>   h e l l o
> How do I output something using 'print' such that there is no new line or 
> space appended at the end of the output.

> 

> Hehe... just answered my own question:
>   import sys
>   for c in 'hello' : sys.stdout.write(c)
> Is this the way to do it or is there a more appropriate approach.

Also

outstring = ''
for c in 'hello':
outstring += c
print outstring

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


Re: [Tutor] script question

2005-09-26 Thread R. Alan Monroe

> for i in passwordlist:
>   if i == port:
> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + " " +
>sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])

If you don't have duplicates in your list, a "break" after the
os.system line might help, because once you've found what you're
looking for you can skip the rest.


> I'd like to know if there is a more efficient way to do this and if there is
> a way to have these functions performed with the least amount of time
> possible (the ini file could grow quite large).

If you wanted to get tricky you could do things like sort the list and
do a binary search on it instead of a linear search.

Alan

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


Re: [Tutor] 2 questions......novice but not beginner

2005-09-27 Thread R. Alan Monroe
> I need to know how to render graphics without the windowed enviroment.I
> know with pygame you can have a windowless enviroment but I need to be able
> to have only the graphics i choose displayed on the screen without pygame
> filling the rest of the screen with black if thats possible.


Not sure if this is what you mean, but pygame can run within a normal
window (and you choose the size). It doesn't HAVE to be fullscreen. Is
that what you mean?


Alan

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


Re: [Tutor] Embedding

2005-09-27 Thread R. Alan Monroe
> Well we are three programmers. I know python, another knows Java and the
> other C++. We are trying to figure out how to combine all three 
> langauges to make a game.

I checked out this book from the local library:
MUD Game Programming by Ron Penton
http://www.amazon.com/exec/obidos/tg/detail/-/1592000908/qid=1127867592/sr=2-1/ref=pd_bbs_b_2_1/103-5133587-6168643?v=glance&s=books

It had a chapter on how to embed Python in a C++ program. Might be
worth a glance through.

Alan

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


Re: [Tutor] Frustrated Beginner

2005-09-28 Thread R. Alan Monroe
> I am trying to learn Python to use in my lesson plans. I am using Windows XP 
> and the textbooks I am using are Beginning Python by WROX and Learning 
> Pyhton by O'Reilly.

> I am definning a range of words 0 to 55, if the number is divisible by 
> 3,7,11 with no remainder print eggs, else print spam. This works.

> def firstpart():
>for n in range(0, 55):
>   if n % 3 == 0 or n % 7 == 0 or n % 11 == 0:
>   print 'eggs,',
>   else:
>   print 'spam,',
> # Now I am trying to modify the function to replace eggs with toast and spam 
> with jelly. I have spent days and nothing works. Can you send me in the 
> right direction??

It seems like you could just backspace the old words and type the new
words in their place. Unless I misundertand the purpose of the
program.

Alan

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


Re: [Tutor] Generalising system processes

2005-09-29 Thread R. Alan Monroe
> Is there a library in Python that generalises the display of processes
> in the system.
> I am looking for a consistent way of seeing processess, (a python
> equivalent of ps(unix) or tasklist (windows).

> I have googled but the only suggestion I have found was to install ps
> on Windows.

On Windows, you can probably use ctypes module to call
CreateToolhelp32Snapshot()

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/createtoolhelp32snapshot.asp

I have not tried this in Python, though.

Alan

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


[Tutor] Did anyone get the Kamaelia "Conversing" chapter 5 to work?

2005-10-06 Thread R. Alan Monroe
I was working through their tutorial:

> * http://kamaelia.sourceforge.net/MiniAxon/

Chapter 5 claims the output should be:
Hello World 2
Hello World 3
...
Hello World 97
Hello World 98

But mine outputs only:
Hello World 2
(no further output)

I can see in Pythonwin's debugger that p.boxes['outbox'] fills up with
the hundred or so messages intended for display, but they never get
displayed. I suspect an indentation problem, but I can't spot it, even
stepping through in the debugger.

Alan#=
class microprocess(object):

def __init__(self):
super(microprocess, self).__init__()

def main(self):
yield 1

#=
class scheduler(microprocess):

def __init__(self):
super(scheduler, self).__init__()
self.active = []
self.newqueue = []

def main(self):
for x in xrange(100):
for current in self.active:
yield 1
try:
result = current.next()
if result is not -1:
self.newqueue.append(current)
except StopIteration:
pass
self.active = self.newqueue
self.newqueue = []

def activateMicroprocess(self, someprocess):
microthread = someprocess.main()
self.newqueue.append(microthread)

#=
class postman(microprocess):

def __init__(self, source, sourcebox, sink, sinkbox):
super(postman, self).__init__()
self.source = source
self.sourcebox = sourcebox
self.sink = sink
self.sinkbox = sinkbox

def main(self):
yield 1
if self.source.dataReady(self.sourcebox):
postdata = self.source.recv(self.sourcebox)
self.sink.send(postdata, self.sinkbox)

#=
class component(microprocess):

def __init__(self):
super(component, self).__init__()
self.boxes = { 'inbox': [], 'outbox': [] }

def send(self, value, boxname):
self.boxes[boxname].append(value)

def recv(self, boxname):
return self.boxes[boxname].pop(0)

def dataReady(self, boxname):
return len( self.boxes[boxname] )

#=
class Producer(component):

def __init__(self, message):
super(Producer, self).__init__()
self.message = message

def main(self):
while 1:
yield 1
self.send(self.message, "outbox")

#=
class Consumer(component):

#~ def __init__(self, tag):
#~ super(Consumer, self).__init__()

def main(self):
count = 0
while 1:
yield 1
count += 1
if self.dataReady("inbox"):
data = self.recv("inbox")
print data, count


p = Producer("Hello World")
c = Consumer()
postie = postman(p, "outbox", c, "inbox")

myscheduler = scheduler()
myscheduler.activateMicroprocess(p)
myscheduler.activateMicroprocess(c)
myscheduler.activateMicroprocess(postie)

for _ in myscheduler.main():
pass
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Did anyone get the Kamaelia "Conversing" chapter 5 to work?

2005-10-06 Thread R. Alan Monroe
>> I can see in Pythonwin's debugger that p.boxes['outbox'] fills up with
>> the hundred or so messages intended for display, but they never get
>> displayed. I suspect an indentation problem, but I can't spot it, even
>> stepping through in the debugger.

> I made exactly the same mistake! You have to put an infinite loop in
> postman.main(). It's in the directions but I guess it's easy to
> miss.

Bingo, you da man.

Alan

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


Re: [Tutor] Did anyone get the Kamaelia "Conversing" chapter 5 to work?

2005-10-06 Thread R. Alan Monroe
> I've just double checked what happens when running the contents of that
> page, and it works as expected (here at least), so I suspect the problems
> you're seeing are simply due to "code being in HTML" issues.

Yeah I was writing as much as I was able on my own rather than
copying/pasting the code, so it was mainly an oversight in my own
work.

Alan

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


Re: [Tutor] Did anyone get the Kamaelia "Conversing" chapter 5 to work?

2005-10-08 Thread R. Alan Monroe
> On Friday 07 October 2005 03:04, R. Alan Monroe wrote:
> That's great to hear - not the oversight part but the fact you were talking
> about your work. Out of interest, how did you find the tutorial/exercises and
> what level of experience would you say you have?

Around 2-3 years with Python. But I had never used generators (was
aware of them but never had a need) so that was the primary chunk of
the learning curve.

Alan

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


Re: [Tutor] Please look at my wordFrequency.py

2005-10-10 Thread R. Alan Monroe
> IDLE's debugger isn't pretty but it does work, try it.
> Use the context menus and mouse to set a break point,
> then just step through using the step and next buttons.

Has anyone else experienced this? I tried debugging in IDLE with the
source checkbox enabled, but when the sourcecode window lost focus as
I clicked back on the debugger window to hit the step button, the
highlight indicating the current line of source was no longer visible.
It's probably a fluke of Windows XP's GUI theme system, but I was
curious if anyone else had seen it.

Alan

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


Re: [Tutor] comiling python to microchip?

2005-10-12 Thread R. Alan Monroe
> From: "Jeff Peery" <[EMAIL PROTECTED]>
>> is it possible to take python code and compile it for use in a 
>> microprocessor?
>>

> In the same way that Sun have been threatening to build a chip that has Java
> as its machine code then it would be possible to build a chip that ran 
> Python
> bytecode but it would be a huge investment.

> Its certainly not possible woth current Python to generate code that can run
> outside of an operating system on a microchip. ON the otherhand if that
> chop is running even a basic operating system that supports a C compiler
> then it should be possible to build the Python interpreter for the chip/OS
> combo and use python that way.

> In other words, no, you can't currently get a completely standalone
> machine code program from Python code at present. It would be
> feasible to port Python to most micro chip OSs such as CP/M,
> PSOS, QXL(?) etc and its possible that some such port has already
> been done but I don't know of it.

Something I noticed while playing with the dis module is that the
python virtual machine appeared to use the same opcode for adding both
integers and strings, for instance. It would be tricky, or slow, to
translate this into other languages, I bet.

Alan

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


Re: [Tutor] : Threads?

2005-10-22 Thread R. Alan Monroe

> I wanted to find out whether os.system() calls block other threads.
> It seems that they don't. (That's a good thing, it means it should
> work for you!) Here is a program to test this:

For threads that run longer than a few seconds, you can visibly verify
this with Sysinterals Process Explorer. Super useful tool.

Alan

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


Re: [Tutor] os.system sending of break signals

2005-10-27 Thread R. Alan Monroe
>> I send a command to os.system(cmd) and want to send a break signal in 
>> the same way. Is this possible? The break signal is ctrl c (^c).
>> I tried this, but it didn't work: os.system('\x03') I think Hex 03 is 
>> the signal for ctrl c.

> Its not possible with os.system because os.system runs the called 
> program to completion in a separate process. You would need to 
> mess about with threads and process ids to do it that way. However 
> if you use popen() (or maybe popen2()? )you should be able to send 
> a Ctrl-C character to the process. However whether that actually 
> terminates it will depend on the OS, the process and whether 
> Ctrl-C is being caught anywhere. But at least there's a chance 
> of it working!

Python has a "signal" module in the standard library. Will that work?

Alan

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


Re: [Tutor] Can anyone help me?

2005-10-27 Thread R. Alan Monroe
> Hey all,
> I am trying to create a program that draws 6 numbers between 1 and 49 at 
> random for creating lottery tickets. I want to have a better chance when I 
> play. Can anyone help me code this or show me how
> to, please?

Create (empty for now) list to hold your final numbers.
Have a for-loop that runs 6 times using range(6)
Inside the loop, just pick a random number and append it to your final
number list.

Alan

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


Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread R. Alan Monroe
> Unfortunately, I don't understand how list comprehensions work and how to
> implement them.  Can someone point me in the right direction, please.   

 
Compare these two pieces of code


x=[1,2,3,4]
y=[]
for eachnum in x:
y.append(eachnum * 2)


versus

x=[1,2,3,4]
y = [each * 2 for each in x]



Try them both on your box :^)

Alan

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


Re: [Tutor] while/if/elif/else loops

2005-10-31 Thread R. Alan Monroe

> while tosses = 100<0:

I didn't run the program, but this immediately caught my eye as
looking kind of suspect. Was it a typo? Most programs usually
have a need for comparisons of equal, or greater/less, but it's really
rare to need both combined in one statement...

Also if you really _do_ want to check two things being equal, don't
forget to use double equal ( == ).

Alan

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


  1   2   >