Re: [Tutor] Character Buffer Object Error

2012-02-08 Thread Alan Gauld

On 08/02/12 05:56, Michael Lewis wrote:


I've tried the following code, but I am getting the following error. How
do I do this properly?


Christian answered the reason for the error.
Here are some other comments...


def AlterInput(user_input):
 print user_input
 new_output = ''


make this a list not a string


 for index, char in enumerate(user_input):


you don;t need index or enumerate just a simple for loop.


 if char.isdigit():
 new_char = int(char)
 new_char += 1


How will you handle 9? Insert 10 or lose the 1 (or the zero?)
Your choice... I'll assume you insert 10


 new_output = ' '.join(user_input)


I gave no idea what this is for, why insert spaces?
Instead append new_char as a str to the list
new_output.append(str(new_char))

This needs to be outside the if statement because
you want to add all the chars. You will need to play with the 
assignments to make that work but it should be a lot simpler...


At the very end join the list back to a string:

return ''.join(new_output)


 new_output.replace(char, new_char)


You don't need this with a list


 print new_output


Best to keep print statements outside the function and just return the value



 AlterInput(user_input.split())


You don't need to split, just pass in the users string.

HTH,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] python editor

2012-02-08 Thread Jamie Paul Griffin
On Mon, Feb 06, 2012 at 06:11:13PM +, Alan Gauld wrote:
 On 06/02/12 17:17, bob gailer wrote:
 On 2/6/2012 10:25 AM, Kapil Shukla wrote:
 
 Please also suggest a free editor for python which can at least repeat
 previous command with a key stroke
 
 That depends on the editor's mode of operation.
 In an editor like vi (elvis, vim etc) there is a repeat key (the period)
 that repeats most things because most things are a command - even
 inserting text. but in a so called modeless editor (most modern
 ones)
 repeat will be restricted to things that are recognised as atomic
 operations, like search/replace, change case etc. And some of those
 will only be valid when text is selected (so not really modeless!).
 
 Other editors like emacs allow you to specify how often an action is
 repeated. So esc-16 n will insert 16 n's for example.
 
 You would need to be more specific in terms of what you want in a
 repeat operation.
 
 -- 
 Alan G
 Author of the Learn to Program web site
 http://www.alan-g.me.uk/
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
 
 !DSPAM:4f3018592251995719914!
 
 
My personal choices are nvi for command line editor and TextMate for GUI on Mac 
OS X. I don't use Windows systems so haven't a clue what's on offer for that 
platform. I learned nvi just because it's the default editor installed on 
NetBSD base system which is my primary computing platform. There's just so many 
editors now it's difficult to know what will suit you best. It would mostly 
come down to the environment you are most comfortable working in; I spend 90% 
of my time in a UNIX shell so the command line editors suit me better.

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


[Tutor] general basic question

2012-02-08 Thread ken brockman
Hello all:
I have a general and very basic question if I may. I am in the process 
of attempting to write my first python app. I wanted to collect information and 
save it to lists and dictionaries. My question is, is it possible to save said 
lists and dictionaries in the program proper, or do i need to save the 
information to files on the hard drive. I apologize for the simplistic nature 
of my query. I have been reading various python books on and off for well over 
a month and I have to admit i am having a hard time ingesting the concepts. I 
have been googling and perusing articles and books but i can't grasp more then 
the most basic of concepts of what i'v gone over. I'm not looking for any thing 
more then a yes or no, I plan on beating my head against python until it starts 
to sink in or it kills me. Any help would be greatly appreciated.
thank you___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] general basic question

2012-02-08 Thread Walter Prins
Hi Ken,

Welcome to Python and to programming in general.

On 8 February 2012 13:40, ken brockman krush1...@yahoo.com wrote:
 Hello all:
 I have a general and very basic question if I may. I am in the process
 of attempting to write my first python app. I wanted to collect information
 and save it to lists and dictionaries. My question is, is it possible to
 save said lists and dictionaries in the program proper, or do i need to save
 the information to files on the hard drive.

You would save the information in files external and seperate to the
source code of your program.  Note however that you can in fact
directly serialize or persist (fancy object oriented terms that
basically means to save to permanent storage, e.g. disk) Python
objects very easily with Python standard functionality, referred to in
Python terms as pickling.  See the pickle module for  more
information:  http://docs.python.org/library/pickle.html Note that it
is more common for applications to use a database for data storage,
such as SQLite, Postgres, MySQL, SQL Server etc etc, rather than
simple pickling, but for simple cases it (or even simple text files)
might suffice.  It all depends on your requirements... ;)

Regards

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


Re: [Tutor] Character Buffer Object Error

2012-02-08 Thread bob gailer

On 2/8/2012 12:56 AM, Michael Lewis wrote:
I want to find all digits in a string and then increment those digits 
by 1 and then return the same string with the incremented digits.

[snip]

You got lots of good advice from others and some not-so-good advice.

Michael said:
2. The following line appears wrong.
 new_output = ' '.join(user_input)
He did not say why!


I add:

Master the art of Desk Checking.

Take pencil  paper.

Write down the input and output of each statement as though you were the 
computer.



Also learn to read the  understand the Python Manuals:

str.replace(old, new[, count])
Return a copy of the string with all occurrences of substring old 
replaced by new. If the optional argument count is given, only the first 
count occurrences are replaced.


Notice return a copy. It does NOT say that this will convert old in place.

No one else caught this problem!

Since this is homework we we probably should not be offering alternative 
solutions.


However I can't resist offering the one-line solution:

''.join(str(int(x)+1) if x.isdigit() else x for x in 'user_input)

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

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


[Tutor] general basic question

2012-02-08 Thread ken brockman
On 8 February 2012 13:40, ken brockman krush1...@yahoo.com wrote:
 Hello all:
 I have a general and very basic question if I may. I am in the process
 of attempting to write my first python app. I wanted to collect information
 and save it to lists and dictionaries. My question is, is it possible to
 save said lists and dictionaries in the program proper, or do i need to save
 the information to files on the hard drive.


Python
objects very easily with Python standard functionality, referred to in
Python terms as pickling.  See the pickle module for  more
information:  http://docs.python.org/library/pickle.html


Thank you Walter for your help and speedy reply.

Using pickling I have somehow managed to save two separate lists, but the 
dictionary is giving me much more of a struggle.
I will reference the link you were gracious enough to provide me. Hopefully a 
few pots of coffee and my last few remaining brain cells will get me through it.
Thanks again...
PS the last few times i had attempted reading the docs on the python site, 
well, I might as well have been reading a book in  ancient Sanskrit.
But if at first you don't succeed,try, try, try, again.
Have a great day. 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python editor

2012-02-08 Thread R.S.
I'm using Spyder (http://code.google.com/p/spyderlib/) and Notepad++ on
Windows.

I don't like pycharm. This software is consuming too much resources witch
for me is poinless. Pycharm can eat even 500MB+ of RAM for simple
application.

2012/2/8 Jamie Paul Griffin ja...@kontrol.kode5.net

 On Mon, Feb 06, 2012 at 06:11:13PM +, Alan Gauld wrote:
  On 06/02/12 17:17, bob gailer wrote:
  On 2/6/2012 10:25 AM, Kapil Shukla wrote:
  
  Please also suggest a free editor for python which can at least repeat
  previous command with a key stroke
 
  That depends on the editor's mode of operation.
  In an editor like vi (elvis, vim etc) there is a repeat key (the period)
  that repeats most things because most things are a command - even
  inserting text. but in a so called modeless editor (most modern
  ones)
  repeat will be restricted to things that are recognised as atomic
  operations, like search/replace, change case etc. And some of those
  will only be valid when text is selected (so not really modeless!).
 
  Other editors like emacs allow you to specify how often an action is
  repeated. So esc-16 n will insert 16 n's for example.
 
  You would need to be more specific in terms of what you want in a
  repeat operation.
 
  --
  Alan G
  Author of the Learn to Program web site
  http://www.alan-g.me.uk/
 
  ___
  Tutor maillist  -  Tutor@python.org
  To unsubscribe or change subscription options:
  http://mail.python.org/mailman/listinfo/tutor
 
  !DSPAM:4f3018592251995719914!
 
 
 My personal choices are nvi for command line editor and TextMate for GUI
 on Mac OS X. I don't use Windows systems so haven't a clue what's on offer
 for that platform. I learned nvi just because it's the default editor
 installed on NetBSD base system which is my primary computing platform.
 There's just so many editors now it's difficult to know what will suit you
 best. It would mostly come down to the environment you are most comfortable
 working in; I spend 90% of my time in a UNIX shell so the command line
 editors suit me better.

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

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


[Tutor] how to change the current working directory path in ipython.

2012-02-08 Thread Debashish Saha
how to change  the current working directory path in ipython.

my current directory path is
   pwd
   Out[2]: u'C:\\Users\\as'

now if i want to take the path to a subfolder of above
'C:\\Users\\as', what do i have to do?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] general basic question

2012-02-08 Thread Walter Prins
Hi Ken,

On 8 February 2012 14:17, ken brockman krush1...@yahoo.com wrote:
 Thank you Walter for your help and speedy reply.
You're welcome.

 Using pickling I have somehow managed to save two separate lists, but the
 dictionary is giving me much more of a struggle.

Well do post back if you don't manage to solve your issues (with full
error messages  stack traces as relevant please.)  Re dictionaries --
I actually forgot to mention, there's a specialized type of dictionary
class available in Python, called a shelf, implented/available via
the shelve module, which is basically a dict with pickling built in.
 See here:
http://docs.python.org/library/shelve.html

HTH,

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


Re: [Tutor] how to change the current working directory path in ipython.

2012-02-08 Thread Joel Goldstick
On Wed, Feb 8, 2012 at 9:24 AM, Debashish Saha silid...@gmail.com wrote:
 how to change  the current working directory path in ipython.

 my current directory path is
                       pwd
               Out[2]: u'C:\\Users\\as'

 now if i want to take the path to a subfolder of above
 'C:\\Users\\as', what do i have to do?
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


Try looking here:
http://docs.python.org/tutorial/stdlib.html#operating-system-interface

There is a module in python called os

Here is an example from the documentation

 import os
 os.getcwd()  # Return the current working directory
'C:\\Python26'
 os.chdir('/server/accesslogs')   # Change current working directory
 os.system('mkdir today')   # Run the command mkdir in the system shell
0

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


[Tutor] PyQT GUI Threading example

2012-02-08 Thread R.S.
I can't find any full example of threading with many threads working and
updating GUI (precisely i need QTreeWidget). I can only find: not updating
GUI examples, updating GUI examples with one thread. But i just can't find
what i need. Could anyone share working example with many threads updating
GUI like for example connecting to several www sites and adding the
response in a list on QTreeWidget?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python editor

2012-02-08 Thread Tino Dai
On Wed, Feb 8, 2012 at 9:17 AM, R.S. zorean...@gmail.com wrote:

 I'm using Spyder (http://code.google.com/p/spyderlib/) and Notepad++ on
 Windows.

 I don't like pycharm. This software is consuming too much resources witch
 for me is poinless. Pycharm can eat even 500MB+ of RAM for simple
 application.


 2012/2/8 Jamie Paul Griffin ja...@kontrol.kode5.net

 On Mon, Feb 06, 2012 at 06:11:13PM +, Alan Gauld wrote:
  On 06/02/12 17:17, bob gailer wrote:
  On 2/6/2012 10:25 AM, Kapil Shukla wrote:
  
  Please also suggest a free editor for python which can at least repeat
  previous command with a key stroke
 
  That depends on the editor's mode of operation.
  In an editor like vi (elvis, vim etc) there is a repeat key (the period)
  that repeats most things because most things are a command - even
  inserting text. but in a so called modeless editor (most modern
  ones)
  repeat will be restricted to things that are recognised as atomic
  operations, like search/replace, change case etc. And some of those
  will only be valid when text is selected (so not really modeless!).
 
  Other editors like emacs allow you to specify how often an action is
  repeated. So esc-16 n will insert 16 n's for example.
 
  You would need to be more specific in terms of what you want in a
  repeat operation.
 
  --
  Alan G
  Author of the Learn to Program web site
  http://www.alan-g.me.uk/
 
  ___
  Tutor maillist  -  Tutor@python.org
  To unsubscribe or change subscription options:
  http://mail.python.org/mailman/listinfo/tutor
 
  !DSPAM:4f3018592251995719914!
 
 
 My personal choices are nvi for command line editor and TextMate for GUI
 on Mac OS X. I don't use Windows systems so haven't a clue what's on offer
 for that platform. I learned nvi just because it's the default editor
 installed on NetBSD base system which is my primary computing platform.
 There's just so many editors now it's difficult to know what will suit you
 best. It would mostly come down to the environment you are most comfortable
 working in; I spend 90% of my time in a UNIX shell so the command line
 editors suit me better.


I'm using vim with a number of plugins to turn the text editor into a
Python IDE. Some of the setup highlights are:

 * code highlighting
 * syntax checking
 * code folding
 * and a whole bunch more

For more information: http://sontek.net/turning-vim-into-a-modern-python-ide


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


[Tutor] confusion about scipy

2012-02-08 Thread Debashish Saha
ImportError   Traceback (most recent call last)
C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
execfile(fname, glob, loc)
166 else:
167 filename = fname
-- 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):

C:\Users\as\hemanta\noorm.py in module()
  1 import numpy as np
 2 from scipy import brentq
  3 import matplotlib.pyplot as plt
  4 from pylab import twinx
  5 from scipy.integrate import quad

ImportError: cannot import name brentq


Question:
like 'from pylab import twinx' why could not i write 'from scipy
import brentq'.Instead i have to write 'from scipy.optimize import
brentq'.But why???
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] confusion about scipy

2012-02-08 Thread Evert Rol
 ImportError   Traceback (most recent call last)
 C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
 execfile(fname, glob, loc)
166 else:
167 filename = fname
 -- 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):
 
 C:\Users\as\hemanta\noorm.py in module()
  1 import numpy as np
  2 from scipy import brentq
  3 import matplotlib.pyplot as plt
  4 from pylab import twinx
  5 from scipy.integrate import quad
 
 ImportError: cannot import name brentq
 
 
 Question:
 like 'from pylab import twinx' why could not i write 'from scipy
 import brentq'.Instead i have to write 'from scipy.optimize import
 brentq'.But why???

Because that's where the scipy developers put the brentq function: in the 
optimize module.
It's basically the same as your line 5, where quad is in the integrate module 
in the scipy package.

It makes sense to organise a large library into (sub)packages/(sub)modules. 
Just as the tutorial shows as well: 
http://docs.python.org/tutorial/modules.html#packages
The fact that twinx can be imported straight from the pylab module, is actually 
just a convenient shortcut.

  Evert

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


[Tutor] general basic question

2012-02-08 Thread ken brockman
 Using pickling I have somehow managed to save two separate lists, but the
 dictionary is giving me much more of a struggle.

Well do post back if you don't manage to solve your issues (with full
error messages  stack traces as relevant please.)  Re dictionaries --
I actually forgot to mention, there's a specialized type of dictionary
class available in Python, called a shelf, implented/available via
the shelve module, which is basically a dict with pickling built in.
See here:
http://docs.python.org/library/shelve.html

HTH,

Walter


Walter, you're the man.
I've read of the shelve command. Not that i understood it, but i've read it. 
I'm going to hit the books and google some more before i waste anymore of your 
time. But if i can't sort it out, I may just take you up on your kind offer.
Have a good day .
Ken___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] general basic question

2012-02-08 Thread Joel Goldstick
On Wed, Feb 8, 2012 at 12:33 PM, ken brockman krush1...@yahoo.com wrote:
 Using pickling I have somehow managed to save two separate lists, but the
 dictionary is giving me much more of a struggle.

 Well do post back if you don't manage to solve your issues (with full
 error messages  stack traces as relevant please.)  Re dictionaries --
 I actually forgot to mention, there's a specialized type of dictionary
 class available in Python, called a shelf, implented/available via
 the shelve module, which is basically a dict with pickling built in.
 See here:
 http://docs.python.org/library/shelve.html

 HTH,

 Walter

 Walter, you're the man.
 I've read of the shelve command. Not that i understood it, but i've read it.
 I'm going to hit the books and google some more before i waste anymore of
 your time. But if i can't sort it out, I may just take you up on your kind
 offer.
 Have a good day .
 Ken

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

You might want to find some tutorials that suit you.  On the right
column of this site there is a list of several online:

www.reddit.com/r/Python/


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


Re: [Tutor] dictionary of methods calling syntax

2012-02-08 Thread Gregory, Matthew
Alan Gauld wrote:
 Since a class is effectively a disguised dictionary I'm not sure why you
 want to do this? If you just want to access the method by name then why
 not just call getattr(spam,'get_mean')?

Thanks for the feedback and, yes, this makes sense.  My use case was when the 
statistic desired was going to be specified at runtime (through file input or 
UI) and that a dictionary would be a convenient crosswalk to associate the 
statistic name with the method name (and thus avoid an if/else ladder).  But I 
understand that as long as there is a direct relationship between the name of 
the statistic and my class method (e.g. 'mean' - get_mean), that I should be 
able to use the getattr() syntax as above.

Thanks also to Joel for the suggestion to put the dictionary inside of __init__.

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


[Tutor] Python Database Scripting

2012-02-08 Thread Brad Hudson
Can someone provide information on the best modules/python tools to use for
general database scripting? I'm interested in something that works across
the board for Oracle, MySQL, MS SQL Server, and DB2. I was hoping a good
generic ODBC module would be out there, but I'm having difficulty locating
one that works for all.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Database Scripting

2012-02-08 Thread Modulok
The closest thing you'll find will probably be the third party module
'sqlalchemy'. You can install it via easy_install or pip. If that doesn't meet
your needs I'm not sure what else would. (But would love to hear about it.)

-Modulok-

On 2/8/12, Brad Hudson brad.hud...@gmail.com wrote:
 Can someone provide information on the best modules/python tools to use for
 general database scripting? I'm interested in something that works across
 the board for Oracle, MySQL, MS SQL Server, and DB2. I was hoping a good
 generic ODBC module would be out there, but I'm having difficulty locating
 one that works for all.

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


Re: [Tutor] dictionary of methods calling syntax

2012-02-08 Thread Mark Lawrence

On 08/02/2012 17:41, Gregory, Matthew wrote:

Alan Gauld wrote:

Since a class is effectively a disguised dictionary I'm not sure why you
want to do this? If you just want to access the method by name then why
not just call getattr(spam,'get_mean')?


Thanks for the feedback and, yes, this makes sense.  My use case was when the 
statistic desired was going to be specified at runtime (through file input or UI) 
and that a dictionary would be a convenient crosswalk to associate the statistic 
name with the method name (and thus avoid an if/else ladder).  But I understand 
that as long as there is a direct relationship between the name of the statistic 
and my class method (e.g. 'mean' -  get_mean), that I should be able to use 
the getattr() syntax as above.

Thanks also to Joel for the suggestion to put the dictionary inside of __init__.

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



This should help if you need more info 
http://code.activestate.com/lists/python-list/403361/


--
Cheers.

Mark Lawrence.

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


Re: [Tutor] (no subject)

2012-02-08 Thread Patrick Dempster
On 07/02/2012 19:07, Hugo Arts wrote:
 On Tue, Feb 7, 2012 at 7:50 PM, Debashish Saha silid...@gmail.com wrote:
 for i in range(1, 8):
print(i)
if i==3:
break
 else:
print('The for loop is over')


  Output:
 1
 2
 3

 Question:but after breaking the for loop why the else command could not work?

 because the else statement was designed to be that way:

 http://docs.python.org/reference/compound_stmts.html#for

 quoting the relevant part:

 When the items are exhausted (which is immediately when the sequence
 is empty), the suite in the else clause, if present, is executed, and
 the loop terminates.

 A break statement executed in the first suite terminates the loop
 without executing the else clause’s suite.

 in short, the else clause only executes if you do *not* break out of the loop.

I might be missing something but I can't see a reason for the else:
clause attached to the for statement, could anyone provide an example
where or why someone might use the else: clause with the for loop?

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


Re: [Tutor] Python Database Scripting

2012-02-08 Thread Alan Gauld

On 08/02/12 18:03, Brad Hudson wrote:

Can someone provide information on the best modules/python tools to use
for general database scripting? I'm interested in something that works
across the board for Oracle, MySQL, MS SQL Server, and DB2. I was hoping
a good generic ODBC module would be out there, but I'm having difficulty
locating one that works for all.


There are a few object-database wrappers such as SQLAlchemy that has 
been mentioned.


But be aware that any such generic database wrapper will have 
compromises in performance/scalability. Every database has its own 
foibles and if you need power access you will need to use native access. 
The Python DBAPI is pretty standard but it also allows you to access the 
database features too.


There is an ODBC wrapper too but of course ODBC adds yet another layer 
of limitations. Given the choice of using ODBC via Python DBAPI or using 
Sqlalchemy I'd probably go with SqlAlchemy.


Either approach is valid, it just depends on whether 
performance/flexibility or compatibility/transparency matters

most. You have to pick your poison.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] Python Database Scripting

2012-02-08 Thread Brad Hudson
Thanks for the responses Alan  Modulok. I will start with SQLAlchemy and
see where it takes me.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] general basic question

2012-02-08 Thread ken brockman



On Wed, Feb 8, 2012 at 12:33 PM, ken brockman krush1...@yahoo.com wrote:
 Using pickling I have somehow managed to save two separate lists, but the
 dictionary is giving me much more of a struggle.


Got it. I manage to get it to save to disk, but only by using the shell to 
create an empty dictionary then pickling it and saving it to a file. Priming 
the pump as it were. I had thought i had read that when you pickle and save a 
list or dictionary to file, if it didn't already exist, it would be created. 
That hasn't been my experience. Had I misunderstood or Am i doing something 
wrong? Just for future reference. I'm as happy as the proverbial pig in 
excrement just to get it to function.
Thanks all for your help.
Ken___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Database Scripting

2012-02-08 Thread Timo

Op 08-02-12 20:20, Brad Hudson schreef:
Thanks for the responses Alan  Modulok. I will start with SQLAlchemy 
and see where it takes me.
I was looking for something similar a couple of months ago and chose to 
use SQLObject over SQLAlchemy. In my eyes it was much easier to use.


Timo




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


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


Re: [Tutor] general basic question

2012-02-08 Thread Robert Berman
On Wed, Feb 8, 2012 at 2:57 PM, ken brockman krush1...@yahoo.com wrote:



 On Wed, Feb 8, 2012 at 12:33 PM, ken brockman krush1...@yahoo.com wrote:
  Using pickling I have somehow managed to save two separate lists, but
 the
  dictionary is giving me much more of a struggle.

 Got it. I manage to get it to save to disk, but only by using the shell to
 create an empty dictionary then pickling it and saving it to a file.
 Priming the pump as it were. I had thought i had read that when you pickle
 and save a list or dictionary to file, if it didn't already exist, it would
 be created. That hasn't been my experience. Had I misunderstood or Am i
 doing something wrong? Just for future reference. I'm as happy as the
 proverbial pig in excrement just to get it to function.
 Thanks all for your help.
 Ken

 Ken,


Let me see if I understand your problem. You are pickling a dictionary and
finding that it will not work unless there already is an existing
dictionary for your pickled dictionary to write over. Otherwise, there is
either no write at all or the write is followed by a delete.  Is that a
reasonable definition of your current problem?

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


[Tutor] general basic question

2012-02-08 Thread ken brockman
Got it. I manage to get it to save to disk, but only by using the shell to 
create an empty dictionary then pickling it and saving it to a file. Priming 
the pump as it were. I had thought i had read that when you pickle and save a 
list or dictionary to file, if it didn't already exist, it would be created. 
That hasn't been my experience. Had I misunderstood or Am i doing something 
wrong?


Let me see if I understand your problem. You are pickling a dictionary and 
finding that it will not work unless there already is an existing dictionary 
for your pickled dictionary to write over. Otherwise, there is either no write 
at all or the write is followed by a delete.  Is that a reasonable definition 
of your current problem? 

Robert Berman

Really close to it Robert. No delete but an error msg. Something akin to file 
dosen't exist, not found , or words to that effect .
 Ken___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] general basic question

2012-02-08 Thread Joel Goldstick
On Wed, Feb 8, 2012 at 4:28 PM, ken brockman krush1...@yahoo.com wrote:
 Got it. I manage to get it to save to disk, but only by using the shell to
 create an empty dictionary then pickling it and saving it to a file. Priming
 the pump as it were. I had thought i had read that when you pickle and save
 a list or dictionary to file, if it didn't already exist, it would be
 created. That hasn't been my experience. Had I misunderstood or Am i doing
 something wrong?

 Let me see if I understand your problem. You are pickling a dictionary and
 finding that it will not work unless there already is an existing dictionary
 for your pickled dictionary to write over. Otherwise, there is either no
 write at all or the write is followed by a delete.  Is that a reasonable
 definition of your current problem?

 Robert Berman

 Really close to it Robert. No delete but an error msg. Something akin to
 file dosen't exist, not found , or words to that effect .
  Ken

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


Ken,

The best way to get help here is to post a small example of your code
that shows the problem, along with the complete traceback.  Although
at first they seem a little daunting, the traceback will make the
problem obvious

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


Re: [Tutor] general basic question

2012-02-08 Thread Alan Gauld

On 08/02/12 21:28, ken brockman wrote:


Really close to it Robert. No delete but an error msg. Something akin to
file dosen't exist, not found , or words to that effect .


Without sight of code it's only a guess but are you creating
the file with the 'wb' mode - ie. write binary? :-

myPickleFile = open(somefilename.dat, wb)

If you are not using the 'b' for binary pickle and shelve
tend to run into problems, this might be one of those cases.
Its not glaringly obvious from the docs that you need to use
binary mode and beginners often get caught out. Could that be it?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] (no subject)

2012-02-08 Thread Joel Goldstick
On Wed, Feb 8, 2012 at 2:04 PM, Patrick Dempster
pa...@paddy-dempster.org.uk wrote:
 On 07/02/2012 19:07, Hugo Arts wrote:
 On Tue, Feb 7, 2012 at 7:50 PM, Debashish Saha silid...@gmail.com wrote:
 for i in range(1, 8):
    print(i)
    if i==3:
        break
 else:
    print('The for loop is over')


  Output:
 1
 2
 3

 Question:but after breaking the for loop why the else command could not 
 work?

 because the else statement was designed to be that way:

 http://docs.python.org/reference/compound_stmts.html#for

 quoting the relevant part:

 When the items are exhausted (which is immediately when the sequence
 is empty), the suite in the else clause, if present, is executed, and
 the loop terminates.

 A break statement executed in the first suite terminates the loop
 without executing the else clause’s suite.

 in short, the else clause only executes if you do *not* break out of the 
 loop.

 I might be missing something but I can't see a reason for the else:
 clause attached to the for statement, could anyone provide an example
 where or why someone might use the else: clause with the for loop?

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


Here is and interesting article:
http://nedbatchelder.com/blog/201110/forelse.html

The else clause runs if the loop breaks for some reason.  So you would
use it only to do some processing if the loop completes completely.
-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] For/else construct was: Re: (no subject)

2012-02-08 Thread Alan Gauld

On 08/02/12 19:04, Patrick Dempster wrote:


I might be missing something but I can't see a reason for the else:
clause attached to the for statement, could anyone provide an example
where or why someone might use the else: clause with the for loop?



There have been a couple of sample cases given already but here is an 
example of what you would need to do without it.



broken_loop = False
for item in collection:
 process(item)
 if condition:
broken_loop = True
break
if not broken_loop:
   do_the_else_part()

do_this_regardless()


It's not a huge pain but this is easier:


for item in collection:
 process(item)
 if condition:
break
else:
   do_the_else_part()

do_this_regardless()

HTH,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] (no subject)

2012-02-08 Thread Jerry Hill
On Wed, Feb 8, 2012 at 5:21 PM, Joel Goldstick joel.goldst...@gmail.comwrote:

 The else clause runs if the loop breaks for some reason.  So you would
 use it only to do some processing if the loop completes completely.


No.  The else clause only runs if the loop does NOT break out early.  The
else clause only runs if the loop runs to completion without breaking.

For what it's worth, I loathe for/else loops, and will probably never use
them in my code.  They confuse me every time I see them, and I have to go
look up the behavior.  My brain always jumps to the conclusion that the
else clause should run when we do hit a break, which is the exact
opposite of how it actually works.  Maybe if they had been written into the
language as for/then loops I would remember it correctly.

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


Re: [Tutor] (no subject)

2012-02-08 Thread Joel Goldstick
On Wed, Feb 8, 2012 at 6:00 PM, Jerry Hill malaclyp...@gmail.com wrote:
 On Wed, Feb 8, 2012 at 5:21 PM, Joel Goldstick joel.goldst...@gmail.com
 wrote:

 The else clause runs if the loop breaks for some reason.  So you would
 use it only to do some processing if the loop completes completely.


 No.  The else clause only runs if the loop does NOT break out early.  The
 else clause only runs if the loop runs to completion without breaking.

 For what it's worth, I loathe for/else loops, and will probably never use
 them in my code.  They confuse me every time I see them, and I have to go
 look up the behavior.  My brain always jumps to the conclusion that the
 else clause should run when we do hit a break, which is the exact opposite
 of how it actually works.  Maybe if they had been written into the language
 as for/then loops I would remember it correctly.

 Jerry

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

oops.. sorry.. yes else runs if the loop completes without a break.. duh!


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


Re: [Tutor] general basic question

2012-02-08 Thread Steven D'Aprano

ken brockman wrote:


Really close to it Robert. No delete but an error msg. Something akin to file 
dosen't exist, not found , or words to that effect .



Something akin to?

How about if you copy and paste the actual error message, instead of asking us 
to guess?


That means the full traceback, starting at the line Traceback (most recent 
call last) all the way to the end.


It may also help if you show us the code that you are running, again instead 
of making us guess. But before you do, please read this document:


http://sscce.org/



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


[Tutor] This program has worked for me before.

2012-02-08 Thread Nathaniel Trujillo
Hello, I stopped using python for about 4 months but now I am back. I tried
running my pizza_panic_game.py program again thinking nothing had changed
since a last ran it but boy was I wrong. Are we allowed to send the program
as an attachment? Here is the program

# Pizza Panic
# Player must catch falling pizzas before they hit the ground
from livewires import games, color
import random
games.init(screen_width = 640, screen_height = 480, fps =50)
class Pan(games.Sprite):

A pan controlled by player to catch falling pizzas.

image = games.load_image(pan.bmp)
def __init__(self):
 Initializing Pan object and create Text object for score. 
super(Pan, self).__init__(image = Pan.image, x = games.mouse.x,
bottom = games.screen.height)
self.score = games.Text(value = 0, size = 25, color = color.black,
top = 5, right = games.screen.width - 10)
games.screen.add(self.score)
def update(self):
 Move to mouse x position. 
self.x = games.mouse.x
if self.left  0:
self.left = 0
if self.right  games.screen.width:
self.right = games.screen.width
self.check_catch()
def check_catch(self):
 Check if catch pizzas. 
for pizza in self.overlapping_sprites:
self.score.value += 10
self.score.right = games.screen.width - 10
pizza.handle_caught()
class Pizza(games.Sprite):

A pizza which falls to the ground.

image = games.load_image(pizza.bmp)
speed = 1
def __init__(self, x, y = 90):
 Initialize a Pizza object. 
super(Pizza, self).__init__(image = Pizza.image, x = x, y = y, dy =
Pizza.speed)
def update(self):
 Check if bottom edge has reached screen bottom. 
if self.bottom  games.screen.height:
self.end_game()
self.destroy()
def handle_caught(self):
 Destroy self if caught. 
self.destroy()
def end_game(self):
 End the game. 
end_message = games.Message(value = Game Over, size = 90, color =
color.red, x = games.screen.width/2, y = games.screen.height/2, lifetime =
5 * games.screen.fps, after_death = games.screen.quit)
games.screen.add(end_message)
class Chef(games.Sprite):

A chef which moves left and right, dropping pizzas.

image = games.load_image(chef.bmp)
def __init__(self, y = 55, speed = 2, odds_change = 200):
 Initialize the Chef object. 
super(Chef, self).__init__(image = Chef.image, x =
games.screen.width / 2, y = y, dx = speed)
self.odds_change = odds_change
self.time_til_drop = 0
def update(self):
 Determined if direction needs to be reversed. 
if self.left  0 or self.right  games.screen.width:
self.dx = -self.dx
elif random.randrange(self.odds_change) == 0:
self.dx = -self.dx
self.check_drop()
def check_drop(self):
 Decrease countdown or drop pizza and reset countdown. 
if self.time_til_drop  0:
self.time_til_drop -= 1
else:
new_pizza = Pizza(x = self.x)
games.screen.add(new_pizza)
# set buffer to approx 30% of pizza height, regardless of pizza
speed
self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed)
+ 1
def main():
 Play the game. 
wall_image = games.load_image(wall.jpg, transparent = False)
games.screen.background = wall_image
the_chef = Chef()
games.screen.add(the_chef)
the_pan = Pan()
games.screen.add(the_pan)
games.mouse.is_visible = False
games.screen.event_grab = True
games.screen.mainloop()
# start it up!
main()
and it keeps giving me this error message which I then googled to no avail

Traceback (most recent call last):
  File C:\Python31\pizza_panic_game.py, line 4, in module
from livewires import games, color
  File C:\Python31\lib\site-packages\livewires\games.py, line 57, in
module
import pygame, pygame.image, pygame.mixer, pygame.font, pygame.transform
  File C:\Python31\lib\site-packages\pygame\__init__.py, line 95, in
module
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.

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


[Tutor] bogus characters in a windows file

2012-02-08 Thread Garry Willgoose
I'm reading a file output by the system utility WMIC in windows (so I can track 
CPU usage by process ID) and the text file WMIC outputs seems to have extra 
characters in I've not seen before.

I use os.system('WMIC /OUTPUT:c:\cpu.txt PROCESS GET ProcessId') to output the 
file and parse file c:\cpu.txt

The first few lines of the file look like this in notepad

ProcessId  
0 
4  
568
624
648


I input the data with the lines

infile = open('c:\cpu.txt','r')
infile.readline()
infile.readline()
infile.readline()

the readline()s yield the following output

'\xff\xfeP\x00r\x00o\x00c\x00e\x00s\x00s\x00I\x00d\x00 \x00 \x00\r\x00\n'
'\x000\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00\r\x00\n'
'\x004\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00\r\x00\n'

Now for the first line the title 'ProcessId' is in this string but the 
individual characters are separated by '\x00' and at least for the first line 
of the file there is an extra '\xff\xfe'. For subsequent its just '\x00. Now I 
can just replace the '\x**' with '' but that seems a bit inelegant. I've tried 
various options on the open 'rU' and 'rb' but no effect. 

Does anybody know what the rubbish characters are and what has caused the. I'm 
using the latest Enthought python if that matters.





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


Re: [Tutor] bogus characters in a windows file

2012-02-08 Thread Marc Tompkins
On Wed, Feb 8, 2012 at 5:46 PM, Garry Willgoose 
garry.willgo...@newcastle.edu.au wrote:

 I'm reading a file output by the system utility WMIC in windows (so I can
 track CPU usage by process ID) and the text file WMIC outputs seems to have
 extra characters in I've not seen before.

 I use os.system('WMIC /OUTPUT:c:\cpu.txt PROCESS GET ProcessId') to output
 the file and parse file c:\cpu.txt

 The first few lines of the file look like this in notepad

 ProcessId
 0
 4
 568
 624
 648


 I input the data with the lines

 infile = open('c:\cpu.txt','r')
 infile.readline()
 infile.readline()
 infile.readline()

 the readline()s yield the following output

 '\xff\xfeP\x00r\x00o\x00c\x00e\x00s\x00s\x00I\x00d\x00 \x00 \x00\r\x00\n'
 '\x000\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00\r\x00\n'
 '\x004\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00\r\x00\n'

 Now for the first line the title 'ProcessId' is in this string but the
 individual characters are separated by '\x00' and at least for the first
 line of the file there is an extra '\xff\xfe'. For subsequent its just
 '\x00. Now I can just replace the '\x**' with '' but that seems a bit
 inelegant. I've tried various options on the open 'rU' and 'rb' but no
 effect.

 Does anybody know what the rubbish characters are and what has caused the.
 I'm using the latest Enthought python if that matters.

 You're trying to read a Unicode text file byte-by-byte.  It'll end in
tears...
The \xff\xfe at the beginning is the Byte Order Marker or BOM.

Here's a quick primer on Unicode:
http://www.joelonsoftware.com/articles/Unicode.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] bogus characters in a windows file

2012-02-08 Thread Dave Angel

On 02/08/2012 08:46 PM, Garry Willgoose wrote:

I'm reading a file output by the system utility WMIC in windows (so I can track 
CPU usage by process ID) and the text file WMIC outputs seems to have extra 
characters in I've not seen before.

I use os.system('WMIC /OUTPUT:c:\cpu.txt PROCESS GET ProcessId') to output the 
file and parse file c:\cpu.txt


First mistake.  If you use backslash inside a python literal string, you 
need to do one of two things:

   1) use a raw string
   2) double the backslash
It so happens that \c is not a python escape sequence, so you escaped 
this particular bug.



The first few lines of the file look like this in notepad

ProcessId
0
4
568
624
648


I input the data with the lines

infile = open('c:\cpu.txt','r')
Same thing.  You should either make it r'c:\cpu.txt'   or   
'c:\\cpu.txt'  or  even 'c:/cpu.txt'

infile.readline()
infile.readline()
infile.readline()


OK, so you throw away the first 3 lines of the file.


the readline()s yield the following output

'\xff\xfeP\x00r\x00o\x00c\x00e\x00s\x00s\x00I\x00d\x00 \x00 \x00\r\x00\n'
'\x000\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00\r\x00\n'
'\x004\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00\r\x00\n'

Now, how did you get those bytes displayed;  they've already been thrown 
out.

Now for the first line the title 'ProcessId' is in this string but the 
individual characters are separated by '\x00' and at least for the first line 
of the file there is an extra '\xff\xfe'. For subsequent its just '\x00. Now I 
can just replace the '\x**' with '' but that seems a bit inelegant. I've tried 
various options on the open 'rU' and 'rb' but no effect.

Does anybody know what the rubbish characters are and what has caused the. I'm 
using the latest Enthought python if that matters.
It matters, but it'd save each of us lots of trouble if you told us what 
version that was;  especially which version of Python.  The latest 
Enthought I see is called EPD 7.2.  But after 10 minutes on the site, I 
can't see whether there actually is a Python on there or not.  it seems 
to be just a bunch of libraries for Python.  But whether they're for 
CPython, IronPython, or something else, who knows?



I don't see any rubbish characters.  What I see is some unicode strings, 
displayed as though they were byte strings.  the first two bytes are the 
BOM code, commonly put at the beginning of a file encoded in UTF-16.  
The remaining pairs of bytes are UTF-16 encodings for ordinary 
characters.  Notepad would recognize the UTF-16 encoding, and display 
the characters correctly.  Perhaps you need to do the same.


You showed us a fragment of code which would throw away the first 3 
lines of the file.  You don't show us any code indicating what you mean 
by yield the following output.


So you want us to read your mind, and tell you what's there?



--

DaveA

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


Re: [Tutor] bogus characters in a windows file

2012-02-08 Thread Marc Tompkins
On Wed, Feb 8, 2012 at 6:09 PM, Marc Tompkins marc.tompk...@gmail.comwrote:

 On Wed, Feb 8, 2012 at 5:46 PM, Garry Willgoose 
 garry.willgo...@newcastle.edu.au wrote:

 I'm reading a file output by the system utility WMIC in windows (so I can
 track CPU usage by process ID) and the text file WMIC outputs seems to have
 extra characters in I've not seen before.

 I use os.system('WMIC /OUTPUT:c:\cpu.txt PROCESS GET ProcessId') to
 output the file and parse file c:\cpu.txt

 The first few lines of the file look like this in notepad

 ProcessId
 0
 4
 568
 624
 648


 I input the data with the lines

 infile = open('c:\cpu.txt','r')
 infile.readline()
 infile.readline()
 infile.readline()

 the readline()s yield the following output

 '\xff\xfeP\x00r\x00o\x00c\x00e\x00s\x00s\x00I\x00d\x00 \x00 \x00\r\x00\n'
 '\x000\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00\r\x00\n'
 '\x004\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00\r\x00\n'

 Now for the first line the title 'ProcessId' is in this string but the
 individual characters are separated by '\x00' and at least for the first
 line of the file there is an extra '\xff\xfe'. For subsequent its just
 '\x00. Now I can just replace the '\x**' with '' but that seems a bit
 inelegant. I've tried various options on the open 'rU' and 'rb' but no
 effect.

 Does anybody know what the rubbish characters are and what has caused
 the. I'm using the latest Enthought python if that matters.

 You're trying to read a Unicode text file byte-by-byte.  It'll end in
 tears...
 The \xff\xfe at the beginning is the Byte Order Marker or BOM.

 Here's a quick primer on Unicode:
 http://www.joelonsoftware.com/articles/Unicode.html

 In particular, this phrase:

 we decided to do everything internally in UCS-2 (two byte) Unicode, which
 is what Visual Basic, COM, and Windows NT/2000/XP use as their native
 string type.

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


Re: [Tutor] This program has worked for me before.

2012-02-08 Thread Alan Gauld

On 09/02/12 00:43, Nathaniel Trujillo wrote:

Hello, I stopped using python for about 4 months but now I am back. I



and it keeps giving me this error message which I then googled to no avail
Traceback (most recent call last):
   File C:\Python31\pizza_panic_game.py, line 4, in module
 from livewires import games, color
   File C:\Python31\lib\site-packages\livewires\games.py, line 57, in
module
 import pygame, pygame.image, pygame.mixer, pygame.font,
pygame.transform
   File C:\Python31\lib\site-packages\pygame\__init__.py, line 95, in
module
 from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
thanks for the help.



Looks like a problem with your Livewires installation.

Have you upgraded either Python or Livewires? Or deleted either?
I'd start by reinstalling the correct matching version of Livewires.
ie the one that matches your version of Python.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


[Tutor] What the difference between the two RE?

2012-02-08 Thread daedae11
import re
re.match(^hello, hello)
re.match(hello, hello)

Please give a string that matches RE ^hello but does not match RE hello, or 
matches RE hello but does not match RE ^hello.




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


Re: [Tutor] What the difference between the two RE?

2012-02-08 Thread Christian Witts

On 2012/02/09 08:15 AM, daedae11 wrote:

import re
re.match(^hello, hello)
re.match(hello, hello)
Please give a string that matches RE ^hello but does not match RE 
hello, or matches RE hello but does not match RE ^hello.


daedae11


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
The caret ^ means At the beginning of the line so 'And they said 
hello' will not be matched by the regex pattern '^hello'.


The docs are pretty good on the module
http://docs.python.org/library/re.html
http://docs.python.org/howto/regex.html
--

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


Re: [Tutor] What the difference between the two RE?

2012-02-08 Thread Göran Törnquist

On 2012-02-09 08.16, Christian Witts wrote:

On 2012/02/09 08:15 AM, daedae11 wrote:

import re
re.match(^hello, hello)
re.match(hello, hello)
Please give a string that matches RE ^hello but does not match RE 
hello, or matches RE hello but does not match RE ^hello.


daedae11


___
Tutor maillist  -Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
The caret ^ means At the beginning of the line so 'And they said 
hello' will not be matched by the regex pattern '^hello'.


The docs are pretty good on the module
http://docs.python.org/library/re.html
http://docs.python.org/howto/regex.html
--

Christian Witts
Python Developer



This is also a good source of information for regexp patterns in general:
http://www.regular-expressions.info/

Göran Törnquist
Usertime
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2012-02-08 Thread ken brockman
 Really close to it Robert. No delete but an error msg. Something akin to file 
dosen't exist, not found , or words to that effect .

Something akin to?

How about if you copy and paste the actual error message, instead of asking us 
to guess?
Have been all afternoon'
That means the full traceback, starting at the line Traceback (most recent 
call last) all the way to the end.



I have been trying to post all afternoon to no avail. I keep getting bounced 
back...As per instructions from the list i have resubmitted my original request 
20 times. Not sure of this one will get through either but here goes.
As i had written 20 times before, the issue is resolved, as such no error 
msgs, but will try to replicated it, I seem pretty good at generating error 
msg.: Take 15: sigh,,

def General_info():
file4 = open(Genfacts.p, rb)

Ginfo = pickle.load(file4)
file4.close()
print('General Information: ')
GinfoKey = input('CatKey: ')
GinfoFact = input('Info: ')
Ginfo[GinfoKey] = GinfoFact  # add new key:fact
file4 = open(Genfacts.p, wb)
pickle.dump(Ginfo, file4)
file4.close()
return(Ginfo)
thanks for the good folks who have tried to help.
Ken___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] general basic question

2012-02-08 Thread ken brockman
Really close to it Robert. No delete but an error msg. Something akin to file 
dosen't exist, not found , or words to that effect .

Something akin to?



I'm back on the list again, and if not too late, here is the asked for trace.
 i've managed to replicate the original error msg, by removing the pickled file 
Genfacts.p, from the directory.
Traceback (most recent call last):
File /home/bob/Ninja/ArtyNOW2.py, line 120, in module
Ginfo = General_info()
File /home/bob/Ninja/ArtyNOW2.py, line 69, in General_info
file4 = open(Genfacts.p, rb)
IOError: [Errno 2] No such file or directory: 'Genfacts.p'

elif choice == g:
Ginfo = General_info()
print('General Info is: ',Ginfo)
# espeak routine General info
text = 'General Info is ', Ginfo
cmd = 'espeak -v en+f3 {0} 2/dev/null'.format(text)
os.system(cmd)
elif choice == p:  # Alt. choice != q: incase anything uexpectd inputed
Thanks again
Ken___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor