Re: [Tutor] Strange list behaviour in classes

2010-02-25 Thread Walter Prins
On 25 February 2010 11:22, Dave Angel  wrote:

> The indentation in your code is lost when I look for it --  everything's
> butted up against the left margin except for a single space before def
> variance.  This makes it very hard to follow, so I've ignored the thread
> till now.  This may be caused by the mail digest logic, or it may because
> you're posting online, and don't tell it to leave the code portion
> unformatted.


This is probably something your end, I read and post from within Google mail
(as well as from Thunderbird occassionally) and I have no trouble seeing the
indentation.  (I don't use the mail digest, I receive single emails/posts.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with loops

2010-03-25 Thread Walter Prins
So, am I right that for each X value in file 2, you want to look up to see
if you can find a corresponding line in file 1 where the value from file 2
falls between the X and Y value from file 1, and if found, then output the
original line from file 2 and the 6th column from the found line from file
1?

Is it posible to have multiple entries/lines from file 1 where the value
from file 2 will be found between X and Y in file 1?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to change some words in a text file

2010-03-28 Thread Walter Prins
On 28 March 2010 23:37, Shurui Liu (Aaron Liu)  wrote:

> Tell me how to do what i want, please.
>

Both me and someone else have already told you how to replace a substring in
a string with something else in your earlier question/posting/thread.  If
you've not understood what was written there, then please ask again and
specify what specifically you're having difficulty with.  If however you've
not yet looked into/tried out what we've suggested, then please do try that
first, and then come back if you have problems.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating through a list of strings

2010-05-05 Thread Walter Prins

On 03/05/10 06:16, Thomas C. Hicks wrote:

I am using Python 2.6.4 in Ubuntu.  Since I use Ubuntu (with its every
6 months updates) and want to learn Python I have been working on a
post-install script that would get my Ubuntu system up and running with
my favorite packages quickly.


As an aside, you don't particularly need to write a Python script for 
what you want from scratch, you could look at this script named 
"dpkg-origins" which is also written in Python and is related to what 
you want (it helps dump all installed packages on an existing system): 
http://goonmill.org/static/dpkg-origins


It basically allows you to do this...:

|dpkg-origins > selections.txt|

... which produces a file listing all the packages installed on a 
system.  Obviously you can edit this file manually if you so choose.


Then, you can use the file on a freshly installed machine to reinstall 
all the packages using this pipeline command (here you don't need Python 
or a script as such):


| cat selections.txt | sudo dpkg --set-selections && sudo apt-get -u 
dselect-upgrade |


Not meaning to spoil your fun, but just thought I'd point all that out...

Regards

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


Re: [Tutor] Trying to get this to work - attached is the source code

2010-05-17 Thread Walter Prins
Hi Peter,

We're not familiar with the book, so you'll have to tell us exactly what
you're doing, what you're seeing, and what you're expecting ot see instead.

Suffice it to say, the script seems fine.  When you run it (from an
operating system command prompt) it will print, in the command window, the
output in block letters etc.

You don't really (I suppose) want to be entering those statements directly
into the interpreter (which is what I'm guessing "typing it manually" might
mean), although they should also work.  Obviously the exact output will be
different because if you enter the lines in the program manually into the
interpreter each line will be executed straight after entry.

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


Re: [Tutor] PYTHON 3.1

2010-05-18 Thread Walter Prins
IMHO: If you're new to Python and just trying to learn the language, I'd
suggest sticking to Python 2.x for now, as the vast majority of Python
material out there still use and refer to Python 2.x syntax.   IMHO it'll be
a lot easier learning and coping with what's changed in Python 3 only once
you are already comfortable with Python 2.x syntax, rather than trying to
use materials and books referencing 2.x on 3.x and then consequently running
into unexpected issues as above, and never being sure whether issues you run
into is due to some mistake on your part or a difference between 2.x and
3.x.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-07 Thread Walter Prins
On 7 June 2010 02:37, Alex Hall  wrote:

> I am not sure how else to explain it. I want to loop until the value
> of a variable changes, but while that loop is taking place, the user
> should be able to perform actions set up in a wx.AcceleratorTable.
> Looping, though, causes Windows to tell me that python.exe is not
> responding, so I have to close the entire thing. I guess I am looking
> for a "listener", which will sit in the background and only perform an
> action when it detects a certain thing. In this case, a listener to
> watch for a variable to turn from False to True, then to act when it
> sees that change.
>

Notwithstanding what everyone else have said I'll add the following for what
it's worth:

You need to do some research into how GUI systems typically work,
particularly the message queue and each applications "magic" and hidden
message processing loop etc.  Basically in a GUI app there's a hidden loop
that continually checks for messages (calls) to your application and
dispatches those calls to the handlers defined in your application.
However, if your handlers do not complete quickly, then while they run,
control obviously does not return to this loop again, and consequently no
further events can/will be processed by your app.  Some OS's flag up
applications which do not process their event queues for a while as "not
responding" or similar.

However, in most windowing systems there's a way to process pending messages
that have built up in the queue without actually returning from the handler
that you're in.  In Delphi the call is "Application.ProcessMessages", in VB
it's "DoEvents".  In WxPython it's Yield().  (You can google each of those
to see the same issue in different languages/platforms if you like, it might
be instructive.)

So bottom line, in theory you can call Yield() in your loop and you should
be OK -- your app should suddenly be responsive again even while in the
loop.   This type of solution is however the more "cheap and dirty"
alternative and can introduce it's own set of problems and downsides.  (What
if for example another call/message is processed to the same event handler
from which you called Yield() alrady?  The point is you may open yourself up
to re-entrancy issues if you're not careful.  Also if the loop is very tight
you might end-up consuming a lot of CPU doing nothing, so a sleep() type
call might also be advisable in the loop to prevent spending more time
calling Yield() than doing anything else. )

Anyway, I've done a quick google and the following page seems to be a good
discussion of the above thoughts:
http://wiki.wxpython.org/LongRunningTasks

HTH,

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


Re: [Tutor] finally

2010-06-24 Thread Walter Prins
On 24 June 2010 15:08, Christopher King  wrote:

> so if you encounter an error that you won't handle, but you still to close
> files and save data, you could use finally?
>

More strongly, you *should* use finally, as there's no other way to ensure
your cleanup code will run regardless of unpredictable exceptions that may
be thrown...

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


Re: [Tutor] finally

2010-06-24 Thread Walter Prins
On 24 June 2010 15:34, Chris  wrote:

> cleanup code means code to close files and save data, right
>

Possibly yes, although I'm referring generally to freeing any resources
(objects, memory, files, whatever) your code has acquired/opened that should
be freed whether or not the code succeeds (without throwing an exception) or
fails somehow (having thrown an exception.)

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


Re: [Tutor] Fwd: HELP!

2010-06-28 Thread Walter Prins
On 28 June 2010 21:36, Chris  wrote:

>  My friend jacob had a question. I can't really answer it, but you guys
> can. Send you replies to him not me. Oh, and jacob, I'm forwarding you
> message to the Python Mailing list.
>
> Hi Chris/Jacob,

I'm not sure if it's just me, but I'd have been slightly more interested in
helping and have found it a bit more polite if your friend came to this list
direct with his problem, rather than you basically appearing to be palming
off a support request for something that you started onto strangers on the
Python language tutoring list.  (This isn't exactly a python language
problem either.)

That said: Jacob can you please post *exactly* what you enter, and what
output you get?  (Copy and paste please, don't paraphrase/second guess what
we might want to know.) Suffice it to say that you're likely somehow
entering the command incorrectly.  (I can only speculate at this point that
you're incorrectly including part of the command prompt in your command,
and/or possibly inserting spaces (or omitting them) where needed. )

Regards

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


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-29 Thread Walter Prins
At the risk of adding more fuel to the fire, I'll simply note that

a) I sometimes use Gmail while we visit folks in South Africa who are still
on 56k dial-up.  Initial log-in can be a bit slow, but generally you'd be
surprised at how efficient/quick it is w.r.t bandwidth. (As an aside, with
the amount of mail I receive on a daily basis, using a conventional
"download then read" client on a 56k dial up link would be totally
impractical for me, while by contrast the web-interface allows me to
actually keep on top of my mailbox in a reasonable manner.)
b) Gmail does a lot of in-browser caching, so re-opening a mail you already
opened recently does not instigate another network round trip.  You can test
this by viewing a bunch of emails, then setting your browser into "Work
offline" mode.  You'll see that Gmail will happily re-open emails you've
already opened without requiring a re-fetch.
c) As the web matures the trend towards web-applications being able to store
data locally and run off-line should increase, further improving bandwidth
efficiency on the one hand and end-user experience on the other.  (See fore
example this presentation on HTML 5: http://slides.html5rocks.com/#slide1  )
c) Stating the obvious but you can turn downloading of images off by default
in your browser, which will of course further reduce the actual bandwidth
usage by essentially reducing your web browsing to a text-only stream (which
of course to boot will be compressed between web server and web browser.)
d) Using Gmail means you don't waste bandwidth unneccesarily downloading
mails with big attachments (PDF files, Word files) unless you actually want
to, and also prevents you from having to download hundreds of spam messages
and/or your entire inbox before viewing specific emails, which can eat large
amounts of bandwidth.  (There is of course IMAP as well...)
e) Actually having access to your email from places you wouldn't normally
have access to it (on holiday, at conference) is a benefit you don't
neccesarily have with a conventional client.  (You'll only have it if the
client is on your laptop and you have your laptop with you and you can
connect it to a network allowing internet access. )

As for me, I use gmail but with Thunderbird as mail client on my desktop.
In this way I have the best of both worlds.  When at home I'll download my
mail as normal, when abroad I have an interface accessible from anywhere
with internet access.

I absolutely agree about programmers having to be aware of the bandwidth
costs involved with every operation they do, as bandwidth isn't free.
However, the internet is after all, a network, and the argumentation
ostensibly against web based services (especially potentially relatively low
bandwidth ones like gmail) on the basis that they consume network bandwidth
per-se, seemed a little OTT to me.  YMMV.

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


Re: [Tutor] "x and y" means "if x is false, then x, else y"??

2010-07-05 Thread Walter Prins
On 5 July 2010 08:27, Richard D. Moores  wrote:

> See <
> http://docs.python.org/py3k/library/stdtypes.html#boolean-operations-and-or-not
> >.
> I am quite familiar with the meaning of "x and y" in Python, and how
> it is evaluated -- first x, and only if x is False, then evaluate y.
>

Sorry if this is being overly pedantic, but I thought I'd point out the
above isn't right as stated, although I understand what you're getting at
(re short circuit boolean evaluation) in general.  To be correct, I presume
you meant "OR" where you wrote "AND", as it would be correct in that case
e.g:

x AND y: Will only evaluate y if x is TRUE. (If x is FALSE then you don't
need to evaluate y since the resultant expression will be FALSE regardless,
see footnote 2 in the page you referenced.)

x OR y:  Will only evaluate y if x is FALSE. (If x is TRUE then you don't
need to evaluate y since the resultant expression will be TRUE regardless,
see footnote 1 in the page you referenced.)

See e.g. output of this. 

So then, to explain this line from the page you reference: x and y:
"if *x*is false, then
*x*, else *y"

*Think about it: As per the above, if x is false, then because it's false,
Python need only and will only evaluate x, and will therefore essentially
return whatever "x" is when evaluating the expression.  If x is true on the
other hand, then by the above rules, it has to *also* evaluate y as well,
and so will end up effectively returning whatever y returns as it determines
what the truth value of the overall expression is.  Shortening that
reasoning, you can say, "if x is false, then x, else y". See?  (The same
sory of reasoning applies for the "or" case if you think it out.)
*
*Hope that helps.

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


Re: [Tutor] string to list

2010-08-05 Thread Walter Prins
Just a minor related/tangential suggestion -- O'Reilly had a stand at the
recent EuroPython conference I attended and I was paging through
"Bioinformatics Programming using Python", Book reference:
http://oreilly.com/catalog/9780596154516

Just thought I'd mention it as it seems relevant to the current
question/domain from which the question comes from.

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


Re: [Tutor] word_probles.py

2010-08-08 Thread Walter Prins

Hi,

On 08/08/10 20:01, Shurui Liu wrote:

Okay. I am using WinXP, Python 3.1 on my workstation.
And this is the Python version information I got from putty.exe:
Python 2.5.4 (r254:67916, Apr 13 2009, 18:09:11)
[GCC 4.2.1 20070719  [FreeBSD]] on freebsd7


To add a small comment to what Dave's already said, please refer to the 
official documentation here:

http://docs.python.org/release/3.0.1/whatsnew/3.0.html

The net result for you is, I think, that you should be using Python 2.x 
on your Windows XP box, and not Python 3.x.


Regards,

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


Re: [Tutor] Multiple file open

2010-08-20 Thread Walter Prins


Hello Nitin,

On 20/08/10 16:21, nitin chandra wrote:

import sys,os, fileinput
   

[...]

while True:
try:
line1 = fp1.readline().split(",")
line2 = fp2.readline().split(",")
   

[...]

fp3.write(str3)
   
You're missing the completion for the try/finally block.  Try adding an 
exception handler or comment out the "try" statement for the time being.


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


Re: [Tutor] Databases in Python

2010-08-24 Thread Walter Prins
On 24 August 2010 17:47, aug dawg  wrote:

> if searcher in database:
>> # Figure this out.
>>  if "exit database" in command:
>> print "Bye!"
>> sys.exit()
>>
>
The first thing that caught my eye was the "#figure me out" line -- python
is expecting a statement there, a comment doesn't count.  You can use "pass"
for the time being.  (See
http://docs.python.org/reference/simple_stmts.html#grammar-token-pass_stmt)

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


Re: [Tutor] exercise problem

2010-08-27 Thread Walter Prins
Hi Roelof,

See below

On 27 August 2010 16:05, Roelof Wobben  wrote:

>
> uitkomst = add_vectors[u,v]
>
> But now I get this error message :
>
>
> Traceback (most recent call last):
> *File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 27, in
> *
>
> uitkomst = add_vectors[u,v]
>
> TypeError: 'function' object is not subscriptable
>
>
>
> So it seems that I can't use vectors as a variable in a function.
>
Carefully compare the syntax for calling your function (as in the doctest)
to what you've written above.  See the difference?  (Hint: check the type of
parentheses...)

The error message is giving you a hint -- a subscriptable item is something
like a list or array.  They use square brackets.  Function calls always use
(round) parentheses.  To python, it looks like you're trying to subcript the
function object "add_vectors", which obviously isn't possible.  Hence the
message.

Regards,

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


Re: [Tutor] exercise correct ??

2010-09-06 Thread Walter Prins
Hi Roelof,

On 6 September 2010 18:32, Roelof Wobben  wrote:

>>>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4)
>   6
>
> But in that tuple 5 is on position 3.
>
> Is the exercise here wrong ?
>
>

Not neccesarily...  I notice that the call is similar to the previous test
case, but has an extra parameter "4",  and that but that tuple that's being
searched contains other 5's.  If the extra parameter is interpreted as a
"starting index", then the next index of "5" starting at position 4, would
indeed be 6.  If my guesstimated intention of the test paramters is correct
then there's nothing wrong with the excercise/test and your implementation
of index_of needs to be enhanced to properly handle this extra parameter/new
test case.

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


Re: [Tutor] recursive problem

2010-09-09 Thread Walter Prins
On 9 September 2010 12:59, Shashwat Anand  wrote:

>
> Let's say n, l = 2, [2, 9, [2, 1, 13, 2], 8, [2, 6]]
> Simply Flatten the list l, which will be then be; flatten(l) = [ 2, [2, 9,
> 2, 1,13, 2, 8, 2, 6 ]
> Now count for n; flatten.count(n)
>
>
This is fine except that the excercise probably has to do with introducing
recursion and scoping, which is unfortunately defeated by this solution.

Roelof, look at what you do with the result of the recursive call  which you
currently assign to test and otherwise ignore -- you want to add this to
count and/or return it...

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


Re: [Tutor] recursive problem

2010-09-11 Thread Walter Prins
> That's the whole point! You don't WANT to know what type it is. You want to
> just use it how you want, an if it behaves properly, who cares what type it
> is?
>
> See when you type check you are forcing the user to use those types. What
> if they want to derive a subclass from list? Is there really a reason why
> you should prevent them from using that subclass with your function?
> If there is a valid reason, type checking is fine. But if there isn't, type
> checking is just making your code more inflexible.
>
>
Well, I would submit that if were going to do type checking in such a
context you'd probably check for a base class, so deriving a subclass
wouldn't break entirely.  Your point still stands however, we don't even
want to require from users to derive from class list.  We'd be quite happy
to work with any object that "walks like a list" and "quacks like a list",
that's the beauty of duck typing...

I guess the question to ask/consider is: How can be establish whether a
particular object supports a particular interface/set of behaviours that we
require?  E.g. how do we most pythonically check whether some object "walks
like a list" and "quacks like a list" without tying such code to explicit
type checking?

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


Re: [Tutor] recursive problem

2010-09-11 Thread Walter Prins
Just a quick contribution for what it's worth: One of the subjects being
implicitly talked about here is "introspection" -- you may want to google
that and see else you can find. That said, a nice article covering some of
Python's introspection features is presented here on IBM's site:
http://www.ibm.com/developerworks/library/l-pyint.html

Actually any user
that's used to doing introspection in the Python shell already has that same
tool at their disposal for programmatic introspection, e.g. the dir()
method.  (This is covered in the above article.)

So, perhaps it's an idea to call dir() on a given object and see whether the
object provides the necessary methods to function, e.g. __iter__,
__delitem__, __setitem__ and friends?

Here's some code which constructs a class from scratch, which contains 2
member variables, which are made available via list indexing by implementing
__getitem__ and _setitem__ and shows how you can then use that object as if
it's a list, as least as far as the first 2 elements are concerned.  Also
does some interrogation with dir() at the end.

http://pastebin.com/rRZpbham

Hope that helps,

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


Re: [Tutor] FW: wierd replace problem

2010-09-14 Thread Walter Prins
On 14 September 2010 08:38, Roelof Wobben  wrote:

>
> I understand what you mean but we're talking about a text-file which will
> be read in a string.
> So I can't escape the quotes. As far as I know I can't control  how Python
> is reading a text-file with quotes.
>
>
Putting a value into a string via Python source code is not the same as
putting a value into a string by reading a file.  When you read a file it's
implicit that whatever's in the file (including quotes) will end up in the
string.  There's no ambiguity so no need to worry about escaping.

In Python source code however, quotes have meaning implied by context, so
you have to encode/write strings differently *in source* in order to
disambiguate your intention.  In other words, when Python encounters a first
quote in source code, it interprets this as the start of a string.  When it
encounters the next quote of the same type, it interprets this as the end of
the string, and so on.  If you therefore want to put a quote of the same
type you're using to delineate a string inside of that same string, you need
to "escape" the quote, e.g. tell Python to not interpret the quote as it
normally would and to rather take it literally and as part of the current
string value being read.  This you do by putting a backslash (e.g. \ )
before it.  Of course, the same problem happens when you want to put
backslash itself in a string, so the backslash itself also need to be
escaped in order to be put inside a string in Python.

HTH

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


Re: [Tutor] FW: wierd replace problem

2010-09-14 Thread Walter Prins
On 14 September 2010 11:09, James Mills wrote:

> $ python
> Python 2.6.5 (r265:79063, Jun 13 2010, 14:03:16)
> [GCC 4.4.4 (CRUX)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> s = "foo\"bar'"
> >>> s
> 'foo"bar\''
>

I'd like to point something out here.  Typing "s" as James showed here at
the prompt outputs a version of the string that Python will understand if
fed again, consequently it's encoded to do the same escaping of characters
as you would have to do if you put that expression into your python source
yourself.  If however you entered:

print s

... then Python would've print the value of s as it really is, withou any
escape characters or anything else, e.g.:

>>> print s
foo"bar'

So, even though you see a \' in the output posted by James above, the \ that
was output by Python isn't actually part of the string (e.g. it's not really
there as such), it was only output that way by Python to disambiguate the
value of the string.

So, at the risk of belaboring this point to death, if you do:

s = '\'\'\''

then the contents of the string s in memory is '''

The string does not contain the slashes.  The slashes are only there to help
you make Python understand that the quotes must not be interpreted as the
end of the string, but rather as part of the string.  You could get the
exact same result by doing:

s = "'''"

Here there's no ambiguity and consequently no need for slashes since the
string is delineated by double quotes and not single quotes.

Hope that helps.

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


Re: [Tutor] FW: wierd replace problem

2010-09-14 Thread Walter Prins
Roelof,

On 14 September 2010 17:35, Roelof Wobben  wrote:

> But how can I use the triple quotes when reading a textf-file ?
>

To repeat what I said before, obviously not clearly enough:  All the quoting
stuff, escaping stuff, all of that ONLY APPLIES TO STRINGS/DATA INSIDE OF
YOUR PYTHON CODE.  It does NOT APPLY TO DATA INSIDE OF FILES!  Why not to
files?  Because there's no ambiguity in data inside a file.  It's understood
that everything in a file is just data.  By contrast, in Python code, quote
characters have *meaning*.  Specifically they indicate the start and end of
string literals.  So when they themselves are part of teh string you have to
write them specially to indicate their meaning, either as closing the
string, or as part of the string data.

In a file by contrast, every character is presumed to be just a piece of
data, and so quotes have no special inherent meaning to Python, so they just
represent themselves and always just form part of the data being read from
the file.   Do you understand what I'm saying?  If you have any doubt please
respond so we can try to get this cleared up -- Unless and until you realise
there's a difference between data in a file and string literals in your
python source code you're not going to undertand what you're doing here.

Regards,

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


Re: [Tutor] FW: wierd replace problem

2010-09-14 Thread Walter Prins
On 14 September 2010 21:10, Roelof Wobben  wrote:

> I understand it but I try to understand why in a file there is this 'word
> python makes a "'word.
>

Python doesn't change what it reads from the file.  However, depending on
how you ask Python to tell you what it's read (or what the contents of a
string variable is), it might display it quoted, and/or include escape
charaters, or not as the case may be.  If what you've read from the file
contains quotes, then obviously you need to be careful to not mistake
Python's quoting of the value of a string as being *part* of that string.
Neither must you mistake the escape character (if applicable) from being
actually part of the string.

For example, consider the following exchange in the Python shell (please try
all of this yourself and experiment):

>>> s = 'blah'
>>> s
'blah'
>>> print s
blah
>>>

I assign the value of 'blah' to the string s. So far simple enough.
Obviosuly the quotes used int the assignment of the string does not form
part of the string itself.  Their utility is only to delineate to Python the
start of the string, and the end of the string.

In the next line I ask Python to evaluate the expression s, which it duly
reporst as 'blah'.  Again, it's using normal Python convention to format the
data as a string, because that's what s is, a string object.  But the quotes
are formatting, they're not really part of the string.

In the next line I ask Python to *print *s.  Now, the true content of s is
printed as it is, and hence you can see that the quotes are not part of the
string.

Now consider the following exchange in the Python shell where I open a file
and write some text to it to prove this point:
>>> f = open('test.txt', 'w+')
>>> f.write('blah')
>>> f.close()
>>> import os
>>> os.system('notepad test.txt')

The last line above opens the text file test.txt in Notepad so you can see
the contents.  As you can see, no quotes or anything else.  Now, while open,
suppose we put a single quote in the file, so it reads:
'blah
...and suppose we then save it and exit notepad so you're back in the Python
shell.  Then we do:

>>> f=open('test.txt','r+')
>>> s=f.read()
>>> f.close()
>>> s
"'blah"

Now I've read the contents of the file back into a string variable s, and
asked Python to evaluate (output) this string object.

Notice, Python is now formatting the string with *doube* quotes (previously
it defaulted to single quotes) to avoid having to escape the single quote
that forms part of the string.  If Python had used single quotes instead,
then there would've been an ambiguity with the single quote that's part of
the string and so it would've had to escape that too.  So consequently it
formats the string with double quotes, which is valid Python syntax and
avoids the backslash. (Stating the obvious, strings can be quoted with
double or single quotes.)  As before, the double quotes, as with the single
quotes earlier, are not part of the string.  They are merely formatting
since Python is being asked to display a string and hence it must indicate
the start and end of the string with suitable quote characters.

Now, as before do:

>>> print s
'blah

As before, with print you see the contents of the string as it is (and as
indeed it is also in the file that you saved). Just the single quote you
added at the front of Blah. No double or single quotes or anything else.

Now finally, let's try something a bit more elaborate.  Do again:

>>> os.system('notepad test.txt')

Then put into the file the following 2 lines of text (notice the file now
contains 2 lines, and both single and double quotes...):
+++"+++This line is double quoted in the file and the quotes have + symbols
around them.+++"+++
---'---This line is single quoted in the file and the quotes have - symbols
around them.---'---

Save it, exit Notepad, then do:
>>> f=open('test.txt', 'r+')
>>> s=f.read()
>>> f.close()
>>> s
'+++"+++This line is double quoted in the file and the quotes have + symbols
around them.+++"+++\n---\'---This line is single quoted in the file and the
quotes have - symbols around them.---\'---\n'
>>> print s
+++"+++This line is double quoted in the file and the quotes have + symbols
around them.+++"+++
---'---This line is single quoted in the file and the quotes have - symbols
around them.---'---

Notice we read both lines in the file into one single string.  See how
Python formats that as a string object, and escapes not only the single
quotes but also the line break characters (\n).  See also when Python is
asked to "print" the string, you can see the escape characters really there.
See what's happened?  Do you understand why?

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


Re: [Tutor] FW: wierd replace problem

2010-09-14 Thread Walter Prins
Correction on my last paragraph on my last mail:
"See also when Python is asked to "print" the string, you can see the escape
characters really there." -> "See also when Python is asked to "print" the
string, you can see the escape characters aren't part of the actual contents
of the string."
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Test Drive Development, DocTest, UnitTest

2010-09-22 Thread Walter Prins
You might also have a look at some of the other popular testing frameworks
e.g. Nose (http://somethingaboutorange.com/mrl/projects/nose/0.11.2/) and
py.test (http://wiki.python.org/moin/PyTest)  Both of these have the
advantage that they're discovery based, so they'll go and sniff out tests
from your source, whererver they may be.

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


Re: [Tutor] EXECUTING PYTHON AND SQL STAMENTS

2010-10-05 Thread Walter Prins
Thank you for taking the time to answer. I already changed my os.system()
for your code. I got an error, when I executed this:

> os.system(" 'C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe ' "+arg1
> +" -where "+arg2 +" " +arg3)
> it throws me that "C:/Archivos"  is not recognized as an executable
> external or internal command, programm or file.
> If you really have other opton to fix my problem I'll be thankful because I
> don't have any idea to make this code useful.
>
>
The error message suggests the OS is seeing "C:/Archivos" as the command, as
opposed to the entire path to ogr2ogr.exe, which implies some quoting
issue/quotes being stripped off/lost somewhere along the line.

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


Re: [Tutor] WRITING XLS FROM OS.WALK()

2010-10-08 Thread Walter Prins
On 8 October 2010 20:34, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

> Hello members:
> I developed a Python module to make a list which contains all the files
> ending with .shp and .dbf extensions, I have solved this already, but now I
> want to write an excel file from it. The file should show the full path from
> the found files. This is the code:
>
> import os
> a = open ("directorio.xls","w")
>

Excel (.xls) is not a text format.  What you've written opens
"directorio.xls" as a text file.

If you want to write an Excel format file, have a look at the xlwt (and the
xlrt for reading) Python modules. See http://www.python-excel.org/

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


Re: [Tutor] Hiding Superclass Methods

2010-10-11 Thread Walter Prins
On 11 October 2010 15:55, Adam Bark  wrote:

> You can use __getslice__, __setslice__ etc. methods. They're detailed in
> the list docstrings. Here's an example of using __getslice__
>
> >>> dir([])
> ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
> '__delslice__', '__doc__', '__eq__', '__format__', '__ge__',
> '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__',
> '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__',
> '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
> '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__',
> '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append',
> 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
> >>> print [].__getslice__.__doc__
> x.__getslice__(i, j) <==> x[i:j]
>

Just to add, you might try using "help()" on the various objects and methods
(also objects) to see more contextual and/or formatted information, e.g.

help([])

or help([].__getslice__)

etc.

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


Re: [Tutor] WRITING XLS FROM OS.WALK()

2010-10-11 Thread Walter Prins
On 11 October 2010 14:37, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

> The other question is about the excel files management, if I want to
> manipulate this data to work it in Excel should I look for an excel library
> in python right?
>
>
Yes. I already mentioned one (in my view good) option in my original reply
to you.   The xlwt module works quite well for generating Excel files (with
expectable limitations) from any platform that Python's available on (e.g.
including non-Windows.)  and thus does not require Excel to be available on
the machine you're producing the file on.

If however you are running on Windows and have Excel installed, you could
consider driving the real Excel via COM automation, which will guarantee you
get desired results including formatting, charts etc, and will ensure you
have full access to all the functionality Excel exposes via its COM object
model.

If your requirements on the other hand simple enough then Joel's suggestion
to use CSV is probably preferable.  (The KISS principle: "Keep It Small &
Simple")

There's also the possibility to look into generating .xlsx files (e.g. XML
based Office format files.)  Theoretically you should be able to generate
the correctly structured XML independent of Excel and have it open in
Excel.  I suspect that may be rather painful though (have never tried this
myself) andam almost reluctant to even mention this option, so caveat
emptor.

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


Re: [Tutor] Attempt to overwrite excel cell Python

2010-10-11 Thread Walter Prins
Hi Susana,

On 11 October 2010 21:08, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

>
> *Exception*: *Attempt to overwrite cell*: sheetname='shp' rowx=1 colx=0,
> don't know what is wrong
>
>
This is a default of xlwt behaviour for writing Excel files.  It assumes it
would generally be an unintended mistake to write a cell then overwrite it
later with something else hence it by default raises an exception when this
happens.

Anyway, you can override this behaviour and enable cell overwriting by
adding the parameter "cell_overwrite_ok=True" when you create a worksheet.
However I think you probably are just accidentally (and erroneously)
overwriting the same row accidentally, so the error is probably meaningful
in your case.

Wahtever the case, I've taken the liberty to knock what you posted into
shape a bi -- The following script now works (well it finds files and
doesn't generate the error you reported.)  I've also tidied up the structure
and formatting as you'll see:

http://pastebin.com/Kc9N3DAC

Hope that helps,

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


Re: [Tutor] pickle problem

2010-10-12 Thread Walter Prins
On 12 October 2010 18:35, Roelof Wobben  wrote:

> image = urllib.URLopener()
> image.retrieve("http://www.pythonchallenge.com/pc/def/peak.html","banner.p";
> )
>

OK firstly, image is an URLopener, so whatever URL you specify, that's the
file that it will download.  (I would therefore suggest you give it a
slightly better name next time -- you're after all not even going to be
downloading an image so the name "image" is arguably just confusing.)

Now, back to the problem.  Look closely, what file are you downloading?
Right, you're downloading "http://www.pythonchallenge.com/pc/def/peak.html";

However... that's the HTML page itself!  So, what you're doing is to
download the "peak.html" HTML file from the site, and save it locally as
"banner.p"...

But... what you really want is the "banner.p" file *on the website*.  (As
alluded to in the page source, if you view the web page above in your
browser...)

So..., you need to construct the URL to the "banner.p" pickle file on the
website and then retrieve it.  (Hint: Just replace peak.html with banner.p
in the page URL)   You don't even have to do this with Python, you can fetch
the pickle file by hand with your browser first if you want, just punch the
URL into your browser and watch it download the banner.p file. (But, it's
fun to do it in Python! )

Apologies if I've given away too much!

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


Re: [Tutor] Zip Command

2010-10-14 Thread Walter Prins
On 14 October 2010 07:12,  wrote:

> Does window os have a zip command for python like linux and unix.
> If yes, please what is it.
> If no, please what does it use to create a zip folder.
> I am working on an example in byte of python but the zip command is from
> linux but I use windows.
> Thank you.
>

Windows does not have a command line wrapper for it's zipped folders
functionality (which as you probably know should more properly be called zip
files as that's what they are, notwithstanding the fact that Windows
Explorer makes them look like folders in the UI.)  Several third party
command line versions exist however, including proprietary ones like Winzip
and open source ones. (Google yielded for example this:
http://www.pcreview.co.uk/forums/thread-103518.php )

However, you should perhaps have a look at Python's "zipfile" module which
should be able to create zip files as well.  See e.g.
http://docs.python.org/release/2.5.2/lib/module-zipfile.html

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


Re: [Tutor] Zip Command

2010-10-14 Thread Walter Prins
Alan,

On 14 October 2010 09:51, Alan Gauld  wrote:

> gzip - aka gunzip GNU opensource version - probably your best bet.
>

This is not correct. Gzip zip's format is not the same as the pkzip related
format used by Winzip and other "zip" utilities.  Gzip also only compresses,
it does not deal with multiple files.

Probably the best known open source implemention of the pk related zip
format archivers is Info zip's "zip" and "unzip" packages, available on most
platforms.

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


Re: [Tutor] pythonpath

2010-11-01 Thread Walter Prins
On 1 November 2010 21:57, Chris King  wrote:

>  On 11/1/2010 5:47 PM, Vince Spicer wrote:
> it didn't work
>
>
Then you've done something wrong.  Post the code, and/or the error message,
if any.

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


Re: [Tutor] pythonpath

2010-11-01 Thread Walter Prins
On 1 November 2010 21:58, Chris King  wrote:

>  the first way with work for Window,  the second is for Linux or posix
> systems
>
>  Sorry I can't help with PYTHONPATH on windows.
>
>
To set a PYTHONPATH in Windows, click "Start", right click "My computer",
click "Properties", click "Advanced" tab/section, click "Environment
variables" button.  See if you can find an entry in either the User
variables or the System variables sections named "PYTHONPATH".  If not, add
a new entry to "User variables" by clicking "New", and entering the name
"PYTHONPATH" and whatever you want for the path.  Click "OK", "OK", "OK" and
you should be back to the desktop.  Open the Python shell, and enter:

>>> import sys
>>> print sys.path
['C:\\Python26\\Lib\\idlelib',
'C:\\Python26\\lib\\site-packages\\pip-0.8.1-py2.6.egg', 'C:\\Test',
'C:\\Python26\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib',
'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26',
'C:\\Python26\\lib\\site-packages']

As you can see have an entry "C:\\Test" due to the fact that I created that
as the contents of my "PYTHONPATH" variable.

HTH,

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


Re: [Tutor] argparse: how to use the returned Namespace object?

2010-11-04 Thread Walter Prins
On 4 November 2010 23:20, Mac Ryan  wrote:

> My question boils down to: how can I expand the Namespace object in
> order to get a list of keyword arguments?
>

If "ns" is your Namespace object, then use ns.__dict__, which you can
directly pass to your commands, e.g.

do_stuff(**ns.__dict__)

I'll post a more complete answer if this isn't clear/obvious.

HTH

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


Re: [Tutor] argparse: how to use the returned Namespace object?

2010-11-04 Thread Walter Prins
On 5 November 2010 00:40, Mac Ryan  wrote:
>
> Thank you Walter. I got it and it works! :)
>

Excellent.  I thought I'd mention here you can also create your own
Namespace object (e.g. if you find accessing __dict__ not ideal or something
you can do your own implementation, which will work as long as it's got the
neccesary features.)


> I had previously already inspected "ns.__dict__" with the "dir()"
> function, but couldn't (and can not) see my parameters neither with
> "dir(ns.__dict__)" nor with "dir(ns.__dict__.items)". This is clearly an
> indication that I misunderstand what the __dict__ is and how it works.
>

You need to distinguish between what __dict__ *is*, and what it *contains*.
dir() does introspection, it inspects what an object in Python *is*, e.g.
displays all the methods and attributes of the object.  It does not however
know anything about what (if anything) the object might contain, in the data
storage sense.

A dictionary object is a specific type of container object, it has many
methods but suffice it to say the data (keys and values) inside it are
obviously not explicitly exposed as attribues of the dict object itself. So
then, dir() on a dict object, shows you the methods and attributes of
dict's, but nothing of what data might be inside the dict.

Similarly when you dir() your own instance of an object with some custom
attributes, then likewise, dir() on the object itself will show you the
members and attribues of that object itself.

Now, Python makes available a read-only, "hidden" attribute on all objects
(e.g. a chiled member/object) called "__dict__", into which it encodes the
actual attributes of that object, as key value pairs.  So... if you dir()
the object *itself*, you get information about *its* attributes, if you
however dir() the dict that's part of that object, you'll get a dict's
properties, not what is contained inside of the dicts.

Best,

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


Re: [Tutor] Looking for a tutor to review my code and provide constructive feedback.

2010-11-05 Thread Walter Prins
One final suggestion to add to the others: Install and use both pylint, and
pychecker.  That will help ensure you don't make silly errors or omissions
and follow a consistent coding style that matches the generally accepted
format well.

PyLint: http://pypi.python.org/pypi/pylint
PyChecker: http://pypi.python.org/pypi/PyChecker/0.8.12

Aside: The easiest way to install these (and many other) Python modules is
using "Pip": http://pypi.python.org/pypi/pip/0.8.1

Using Pip, installing pylint is just the following command:

pip install pylint

Likewise for pychecker.

Have a good weekend.

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


Re: [Tutor] Commercial or Famous Applicattions.?

2010-11-08 Thread Walter Prins
Hi Jorge,

Have a look at this page:
http://www.python.org/about/quotes/

A few choice points to maybe make him think:
1.) Python is one of the top 3 languages at Google.  (Where is PHP?...)
2.) Python can be used for GUI apps and has bindings for several GUI widget
sets.  (PHP?)
3.) Python can be used for Command line apps (With some work, PHP can be
too, but it's not exactly natural.)
4.) Python can be used for shell type scripts  (OK, so can PHP, but again
it's not really its forte)
5.) Python can be used for text processing and is good at it (e.g. lxml,
Beautiful soup, good regex support, etc. etc... PHP?)
6.) Python can be used for games (as demonstrated by Eve online for example.
50,000 simultaneous players.  PHP? I think not...)
7.) Python can be used for heavy duty number crunching (e.g. Numpy and
friends.  PHP?...)
8.) Python can be used for image manipulation  (e.g. PIL and friends.
PHP?...)
9.) Python easily runs or is available on multiple platforms, including
Windows, Linux, MacOS, as well as other more esoteric platforms, e.g.
Android phones.  (PHP?)
etc. etc...

I think that's enough for now... you get the picture.  (Obviously I'm a bit
biased ;) )

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


Re: [Tutor] What is a "state variable"?

2010-11-11 Thread Walter Prins
On 11 November 2010 20:11, Richard D. Moores  wrote:

> The term comes up in the 2nd section of
> 
> >
>
>  didn't help.
>
> k = 23
>
> Is k then a state variable in that its state is 23? What sorts of
> variables are, and are not, state variables?
>

My $0.02 worth:

Firstly, the original page somewhat conflates classes and objects, although
this is common and usually the author's meaning can be inferred if one
understands object orientation properly and understand that both classes,
and the objects (instances) made from that class can have their own state.
Usually however people mean that objects (instances) have state variables,
even when they talk about classes. The trouble is that classes are
themselves objects, and can in fact have their own stat.  But, ignore that
for the minute.

So what is state? Well, your toaster has a "powered" state, it's either "on"
or "off".  If you were to create a class to model/represent a toaster (e.g.
from which you can create toaster instances), each of them would be either
"on" or "off".  Now, how would you implement this?  Well, by using a
variable to store what the current state of the toaster object's supposed to
be, e.g. maybe a boolean variable calld "powered_on" that is true when that
instance is supposed to be on, and false otherwise.

So then, any variable (field member of an object) that serves to record what
state an object instance is in, can legitimately be called a state
variable.  Now, the point the original article was making was that if you
have several pure functions (e.g. structured programming style) where the
only scopes available is either full on global or local to each function,
then *every* variable that a function might modify/mutate must be passed to
it as a parameter.  Consequently, if a set of functions collectively operate
on a bunch of data structures, they have to pass all the data to each other
all the time.  This is unavoidable in pure structured languages, except if
you use global variables, which is frowned upon.  Enter object orientation:
If instead however, you turn those functions into a class, you can then
instead have them all "share" the same variable(s) that's commonly visible
to each of them due to paramter passing as shared "state" variables of the
object they belong to, hence removing the need to pass the variables around
all over the place.

To be clear, it might be argued that *any* variable forming part of an
object is by definition some sort of state variable for that object, since
objects having different values for their data members will by definition be
in slightly different states.

Finally, the notion of state is commonly used in computer science, so is
formalised there, some of those formalisms are mentioned in the other page
you reference.

Hope that helps somewhat, ask if that's not clear please.

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


Re: [Tutor] What is a "state variable"?

2010-11-11 Thread Walter Prins
On 11 November 2010 22:47, Walter Prins  wrote:

>  Enter object orientation: If instead however, you turn those functions
> into a class, you can then instead have them all "share" the same
> variable(s) that's commonly visible to each of them due to paramter passing
> as shared "state" variables of the object they belong to, hence removing the
> need to pass the variables around all over the place.
>

Sorry I read my own post and the above doesn't read very well.  Here's an
attempt at improving it:

 Enter object orientation: If instead however, you turn those functions into
a class, you can then instead have them all "share" what would've been
paramters or globals as object-level state variables, hence removing the
need to pass parameters around all over the place.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Grabbing Information from txt files

2010-11-12 Thread Walter Prins
Random thoughts:

1.) Maybe you should be looking at something like Fuppes instead:
http://fuppes.ulrich-voelkel.de/ ?
2.) Even so, continuing with your current direction: there appears to be  a
module/wrapper of MediaInfo for Python, thus removing the need to scrape
information from MediaInfo's output, which is what I presume you're trying
to do above.  Might be useful.  See here:
http://forum.doom9.org/showthread.php?t=96516&page=11

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


Re: [Tutor] Recommend a MVC framework

2010-11-14 Thread Walter Prins
Additionally to what's already been said, you may also want to have a look
at the Pyjamas project (which can work in conjunction with Django as a
back-end), there's a short article about implementing an MVC architecture in
Pyjamas here:
http://pyjs.org/wiki/modelviewcontroller/

Also you may want to have a look at the Python implementation of PureMVC
(which as the previous page mentions can be used in conjuntion with Pyjamas
as well):
http://trac.puremvc.org/PureMVC_Python/

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


Re: [Tutor] program hangs in while loop using wx.yield

2010-11-14 Thread Walter Prins
On 15 November 2010 00:12, Alex Hall  wrote:

> Again: is there a basic tutorial that would explain how control works
> when dealing with a gui, especially one that is meant to last a long
> time but occasionally block input?
>

Normally the way is for the GUI controls (e.g. widgets, grids, objects
whatever you want to call them) to ignore messages (e.g. clicks or keyboard
input or whatever).  To achieve this one can either use
properties/methods/behaviours already available on the widgets being used
(e.g. Buttons have an "Enabled" property that allows you to control whether
they're clickable or not), or you have to implementsuch behaviour yourself,
using some flag/state variables in your application.

As a tiny example, see here: http://pastebin.com/LqJkwpwA

As you can see, each time one of the buttons are clicked, the click handler
alters the buttons' enabled properties which ensures that only the other one
will be clickable next.  This example obviously sidestepped tracking "who's
turn it is" explicitly by directly flipping the Enabled state on the 2
buttons.  In your app I would suppose it'd be better to be explicit about it
and have variables to store this type of information, which can then refer
to in order to decide what to do inside your event handlers.

HTH,

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


Re: [Tutor] program hangs in while loop using wx.yield

2010-11-16 Thread Walter Prins
Not wanting to hijack Terry's conversation, but for what it's worth:

On 16 November 2010 18:08, Patty  wrote:

> If I just can't figure out how to do this with Tkinter and the Python
> Imaging Library, is 'wxPython' the additional software I would want to
> install and try with?  Is its purpose to make GUI event programming easier
> (that would mean the defaults provided are difficult, right? So I shouldn't
> feel bad about being confused?)  If so, can someone explain these additional
> software packages out there?  I mean are they coming from some third
> companies?  And why?  If the software is free.  I'm not understanding the
> history or business part of these Python modules and libraries.  Isn't there
> one organization who is discussing or approving standards for this language?
>

wxPython is a set of Python wrappers for the wxWidgets GUI component set.
wxWidgets in turn is a set of C++ GUI wrapper controls that wraps the native
GUI controls (e.g. edit boxes, memo boxes, drop downs, buttons, radio
buttons, checkboxes, menu's and so on)  on various platforms.

Hence it thus provides a common set of classes/components/controls and
effectively a common API for writing GUI based applications in a cross
platform fashion, e.g. that target multiple platforms (e.g. Mac, Windows,
Unix, Linux etc.)   So, by using wxPython you can write applications knowing
that your app should work pretty much unmodified on any system where
wxWidgets is available/installed.

wxWidgets as well as wxPython is open source, so the source is freely
available and managed/supported by their respective development teams.   For
more see:
http://www.wxwidgets.org/about/
http://www.wxpython.org/what.php

You can download and install wxPython for Windows here (make sure to get the
one corresponding to the version of Python that you have installed.):
http://www.wxpython.org/download.php#stable

You should also install the demo application and documentation.  The demo
application will give you an idea of what you can do and how to do it.

As an aside, there are other similar (competing) libraries that one might
use, e.g. GTK or QT for example (or for that matter TK), which needless to
say also have Python wrappers.  Which to use is largely a matter of context
and taste, but suffice it to say wx is not a bad choice.  It's however quite
large, so don't expect it to all sink in overnight. (I certainly am no wx
expert, I just know enough to be dangerous ;) )

As for Event driven programming, it takes a little getting used to if you're
only used to normal "straight line" programs at this point, GUI programming
adds its own set up of detail and complexity on top of the event-driven
programming model (not least that it usually demands a relatively solid
understanding of OO concepts), so don't feel bad if you're feeling
confused.  (You might want to read up/google "Event driven programming" and
do some research and come back with more questions after you've tried a few
things yourself.)

That's my £0.01 worth anyway,

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


Re: [Tutor] new to python

2010-11-18 Thread Walter Prins
On 18 November 2010 21:13, gary engstrom  wrote:

> Being new to python I was wondering if there is a way to import exel data
> into pyrhon matrix/arrays so that I have some data to work with. I know R
> uses Rcmdr as an easy interface
> for excel data, which helps keep the reader engaged while learning the
> language.
>
>
If you want to read/write an Excel format files, have a look at the "xlwt"
and the "xlrt" Python modules (probably what Steven was aluding to). See
http://www.python-excel.org/

These modules works quite well for reading/generating Excel files (with
expectable limitations) from any platform that Python's available on (e.g.
including non-Windows) and thus does not require Excel to be available on
the machine you're producing the file on.

If however you are running on Windows and have Excel installed, you could
also consider driving the real Excel via COM automation, which will
guarantee you get desired results including formatting, charts etc when
generating sheets, and will ensure you have full access to all the
functionality Excel exposes via its COM object model.

If your requirements is simple enough though then Steven's suggestion to use
CSV is probably preferable, e.g. export the data to CSV and then import with
the "csv" module in Python.  (The KISS principle applies here as elsewhere
in programming: "Keep It Small & Simple")

HTH,

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


Re: [Tutor] new to python

2010-11-19 Thread Walter Prins
On 19 November 2010 00:20, Joel Schwartz  wrote:

> For those of us who are new to writing code that makes various software
> packages interact with each other, can you say more about what "COM object
> model" means in this context and where one can learn how to use it to make
> Python interact with Excel and with Windows software in general. I've seen
> term "COM" before and I know it has something to do with how Windows
> programs interact with each other, but that's about it. Can you suggest some
> resources for learning more?
>

Sure, I'll just add to what Alan and Emile's already said.

The first thing (that's perhaps obvious but I'll just mention it explicitly)
about COM is that it was one of the earlier attempts at solving the
programming language and application interoperability problem.  E.g, how do
we write code so that other languages can easily consume our functionality,
and vice versa?  DDE was an early attempt by Microsoft at a solution, and
COM was an attempt by Microsoft's at a more comprehensive and general answer
to this.  It basically defines a set of standards and API's that effectively
can serve as a language-agnostic bridge between different programming
languages, if those languages are "COM enabled" by their supporting and
complying with COM's requirements.

An important extension or evolution of COM to networks was called DCOM (or
"Distributed Component Object Model".)  As the name aludes, it extends COM
so that it can operate accross a network.  In other words, have a program on
one computer instantiate a component or object (possibly implemented in
another language) on another computer, and work with this object as if it's
a local object part of the lcoal program.   Depending on how well a language
supports and is integrated with COM/DCOM this may and should for the most
part even look like a local native object in the language being programmed
in.

DCOM eventually was further evolved into and eventually included under the
moniker of COM itself, and a set of extensions to DCOM that solved/addressed
a bunch of additional problems/concerns (like security and object pooling,
that you would have to deal with yourself when using only COM/DCOM that
typically occurs in the context of distributed applications) was then called
COM+.   (For more see http://ur.ly/v1Xy and http://ur.ly/v8Ii)

Anyway, suffice it to say, COM and friends introduces its own set of
downsides and issues (suffice it to say I've lost a not insignificant amount
of blood fighting with obscure DCOM security issues in the past), which
eventually was at least one of the reasons for Microsoft eventually coming
up with the .Net framework.  (.Net then, is at one level another attempt at
solving the language interoperability problem in a more seamless and elegant
way.  WSDL and web services standards were another, targetting the program
interoperability accross the web/internet at large, COM/DCOM originally
targetted local area networks and doesn't work very well or easily accross
the internet.)

As for resources, there's a seemingly decent presentation on Python and COM
and friends here: http://ur.ly/voQt

Also there's Activestate's documentation that's appropriate:
http://docs.activestate.com/activepython/2.5/pywin32/html/com/win32com/HTML/GeneratedSupport.html
http://docs.activestate.com/activepython/2.5/pywin32/html/com/win32com/HTML/QuickStartClientCom.html

The package that enables Python to interoperate with COM
applications/languages (as well as making available much of the Windows
Win32 API's as well as the "PythonWin" application) is called "pywin32" and
is available here:
http://sourceforge.net/projects/pywin32/

While the Python package "win32com" which is included in pywin32 (which
enables Python to interoperate with COM applications/languages) provides a
number of ways of querying and accessing COM interfaces with few obvious
differences between them (provided you know the interface), it is usually
more convenient when experimenting to know what methods and properties are
really available for a given interface as well as being more efficient to
use so called "early-binding" when accessing COM objects. This is where the
"makepy" utility comes in. By selecting a particular type library and
building the Python wrappers using this tool in advance, more information
becomes available since you and Python can then refer to the generated
Python wrappers for casual investigation of object interfaces.  All of this
is also covered above in the ActiveState documentation as well as here:
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html

Hopefully that clarifies things a bit. I would suggest you try install the
pywin32 package, then have a go at playing around with Excel perhaps
interactively at first, and then with the tools and examples as outlined in
some of the links I've posted.  (As an aside, obviously I've commented
mostly only on using Python as a COM client, it is also possible to write
COM servers in Python,

Re: [Tutor] Fw: Installing Pyserial for Python27 on Win 7

2010-11-23 Thread Walter Prins
On 23 November 2010 03:02, John Smith  wrote:

> I _assume_ the source is the one that is a tar.gz thingy. Since Windows
> will not handle the unpacking of that, I have to install a
> decompressor/unpacker to do it. Then I can finally get around to installing
> the serial package. Maybe. Unless I run into a similar problem because of
> Win 7 or because pyserial is 32-bit.
>
> I think it is better that I stop now before I install a bunch of extra
> applications that I need only to install one or two Python modules.
>
> I like Python itself. Very powerful. But I guess I'll look for some other
> language which provides the features I need without the hassle. Thanks again
> for your help.
>

Without wanting to be rude: Maybe you shouldn't *assume* anything about
something you apparently know little about and jump to conclusions so
quickly, and rather ask some pertinent questions.  You know what they say
about "assume", it makes an "ass" out of "u" an "me".

Firstly, .tar.gz is more or less the standard archive format for Unix and
Linux based systems (actually it's an archive that's then subsequently
compressed but I digress.)  It's hardly esoteric these days, and there's
numerous archivers that will deal with this format for you on Windows.  It's
a 1 minute problem, literally, to deal with. My favourite on Windows is
IZArc, here: http://www.izarc.org/  Frankly I don't understand why dealing
with this is seen as a lot of hassle or why you're afraid of this cluttering
up your system due to a simple (to you unknown new) file format problem, and
why you assume that implies you'll have 32/64 bit problems as well.

In any case for the record, Python source, especially cross-platform source,
will often be distributed as .tar.gz and oftentimes its actually preferred
to use the source if possible, there's no need to be worried about this or
to fear it in any way.

Furthermore, let me point out that you could even have dealt with this file
with for Python itself , e.g:

> import gzip
> import StringIO
> import tarfile
>
> tardata = gzip.open('c:/pyserial-2.5.tar.gz', 'rb').read()
> tardataIO = StringIO.StringIO(tardata)
> tf = tarfile.TarFile(fileobj=tardataIO)
> tf.extractall('c:/temp')
>

That will uncompress and then extract the file using standard Python.  All
you then have to do is go and run "python setup.py install"  from a command
prompt in the extracted folder, to install it into your Python installation
(which again is an action you'll get quite used to if you're used to using
Python for a while and want to install from source, when you're not using
even easier methods like "easy_setup" or "pip"...)


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


Re: [Tutor] Is Python useful for emulating?

2010-11-27 Thread Walter Prins
On 28 November 2010 02:59, Mauricio Alejandro wrote:

>  I never created any emulator before, and i'm learning C++. Let's say i try
> to write an emulator for... SNES. Would Python be fast enough?
> Also, any useful advice you can give me? Things i should know about before
> i start coding?
>

Because of the performance requirements generally applciable to emulating a
games console, I would not think to write an emulator in native Python.
However you can probably write the main parts that need performance as C
based Python modules, and write "the rest" in Python.  (Whether "the rest"
is substantial enough to warrant it is hard to say.)  This is the route
taken by any Python modules/applications that have critical performance
requirements.

As for useful advice, I don't want to put you off but writing a complete
console emulator is not a trivial project by any stretch of the imagination,
and you'll also need to have very detailed specs about the SNES's hardware
(CPU, video hardware, memory and IO maps, sound hardware etc), as well as
have copies of its firmware (BIOS/ROMS etc) in order to even be able to
begin to work on such a project.  Additionally, there's already (or there
was several years ago) several SNES emulators and doing another one just for
the sake of it, well, is it really worth it?

Maybe something a little more accessible might be to implement a MIPS CPU
emulator, something like this:
http://weblogs.mozillazine.org/roc/archives/2010/11/implementing_a.html
or this:
http://codu.org/projects/trac/jsmips/

And then see how fast you can make that without resorting to C, like the guy
above did in the browser.

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


Re: [Tutor] Pyserial and invalid handle

2010-11-28 Thread Walter Prins
John,

On 28 November 2010 15:55, John Smith  wrote:

> Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)]
> on win32
> Type "copyright", "credits" or "license()" for more information.
>
> >>> import serial
> >>> ser = serial.Serial('com1', timeout = 5)
> >>> x = ser.read()
>
> Traceback (most recent call last):
>  File "", line 1, in 
>x = ser.read()
>  File "E:\Python27\lib\site-packages\serial\serialwin32.py", line 236, in
> read
>raise SerialException("ReadFile failed (%s)" % ctypes.WinError())
> SerialException: ReadFile failed ([Error 6] The handle is invalid.)
> >>>
>

Ugh, you're probably not going to like this.  I've done some googling and it
appears this may be a 64-bit issue with the "ctypes" module... apparently
"64-bit ctypes can only import 64-bit libraries".  See here:
http://ur.ly/vSMQ

Then again, it also seems to be an open issue on the PySerial bug tracker:
http://ur.ly/vZNL

Note, the above ticket suggests that PySerial 2.4 works ok (impliedly even
on 64-bit XP, so I imagine also on Windows 7.)  You should be able to try
this out by downloading the 2.4 version instead and installing it in the
same way you did the 2.5 version.  In any case, it might be an idea to post
a report/add a comment to that bug report as well to maybe help get this
issue resolved.

Cheers,

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


Re: [Tutor] Pyserial and invalid handle

2010-11-28 Thread Walter Prins
Also note this link: http://ur.ly/vVU9

It confirms that PySerial 2.4 works fine on Windows 7 64 bit.  (I've also
just downloaded and checked that installing pyserial 2.4 replaces the
existing pyserial and it does on my Python installation.)

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


Re: [Tutor] Pyserial and invalid handle

2010-11-30 Thread Walter Prins
Hello John



On 29 November 2010 21:44, John Smith  wrote:

> Hi, Walter -
>
> Thanks for all the research. This was my second attempt at installing the
> 2.4 version. I did it thus:
>
> E:\Python27\pyserial-2.4>..\python setup.py install
> standart distutils
> running install
> running build
> running build_py
> creating build
> creating build\lib
> creating build\lib\serial
> copying serial\serialcli.py -> build\lib\serial
> copying serial\serialjava.py -> build\lib\serial
> copying serial\serialposix.py -> build\lib\serial
> copying serial\serialutil.py -> build\lib\serial
> copying serial\serialwin32.py -> build\lib\serial
> copying serial\sermsdos.py -> build\lib\serial
> copying serial\__init__.py -> build\lib\serial
> running install_lib
> running install_egg_info
> Removing E:\Python27\Lib\site-packages\pyserial-2.4-py2.7.egg-info
> Writing E:\Python27\Lib\site-packages\pyserial-2.4-py2.7.egg-info
>
> E:\Python27\pyserial-2.4>
>
>
> But, when I tried it in Python, I got the same as before:
>
>
> >>> import serial
> >>> ser = serial.Serial(0, timeout = 1)
> >>> ser
> Serial(port='COM1', baudrate=9600, bytesize=8,
> parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False,
> dsrdtr=False)
>
> >>> ser.read()
>
> Traceback (most recent call last):
>  File "", line 1, in 
>
>ser.read()
>  File "E:\Python27\lib\site-packages\serial\serialwin32.py", line 236, in
> read
>raise SerialException("ReadFile failed (%s)" % ctypes.WinError())
> SerialException: ReadFile failed ([Error 6] The handle is invalid.)
> >>>
>
>
I've checked and I think it was a mistake to suggest installing pyserial 2.4
on top of 2.5 without first removing 2.5 explicitly.  It appears that doing
so actually still retains the previous version of serialwin32.py in use,
based on the fact that I've manually had a look at serialwin32.py from both
pyserial2.4 and pyserial2.5 and that fact that line 236 in pyserial2.5 is
where the error is raised, and pySerial2.4 by contrast has "if err: #will be
ERROR_IO_PENDING:" on line 236.  Consequently this implies that you're still
using pyserial2.5 above.   (Aside: I originally tested my suggestion for
installing pyserial2.4 and tested it by importing the module (e.g. "import
serial") and then did a "help(serial)" which gave me the impression of it
having done the right thing and using pyserial2.4, but apparently that's not
definitve, or I made a mistake somewhere along the line and got the wrong
end of the stick.)

So. My apologies, but I think that suggestion has added to the confusion.

In any case, to fix it let's delete all instances of pySerial and then
install it again, as follows:

1.) Open up your Python "site-packages" folder in Windows Explorer, e.g.
open up:
E:\Python27\lib\site-packages

2.) Delete any folder named "serial" that you may see.

3.) Delete any *file* name pyserial*.* that you may see, probably you'll see
"pyserial-2.4-py2.7.egg", there may also be an info file.

4.) Open up a Python shell and confirm that you can't import pyserial
anymore (e.g. "import serial" fails with e.g. "ImportError: No module named
serial".  If it still imports then you still have some vestiges of the
existing pyserial installation left over.

5.) After confirming the previous versions are gone, please try reinstalling
it again from scratch.  (E.g. extract source to some suitable place and run
"python setup.py install" from there, which copies the required files into
site-packages etc.)

6.) After installing, confirm "import serial" works again, then try your
test again.

Apologies again for adding to the confusion, and hopefully we're getting
closer. :-(

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


Re: [Tutor] Pyserial and invalid handle

2010-11-30 Thread Walter Prins
Hello John,

On 30 November 2010 16:57, John Smith  wrote:

> Hi, Walter -
>
> I did the above and then got this:
>
> >>> import serial
>
>
> Traceback (most recent call last):
>  File "", line 1, in 
>import serial
>  File "E:\Python27\lib\site-packages\serial\__init__.py", line 18, in
> 
>from serialwin32 import *
>  File "E:\Python27\lib\site-packages\serial\serialwin32.py", line 9, in
> 
>import win32file  # The base COM port and file IO functions.
> ImportError: No module named win32file
> >>>
>
> I guess that file was included in 2.5 but not in 2.4?
>

Apparently so.  Well, win32file is part of the PyWin32 package, which are a
set of modules that wrap many Windows API's.   I'm not sure why it
was't/isn't required for PySerial 2.5 or whether as you say perhaps this
module is included in PySerial2.5 and isn't in 2.4.

But whatever the case may be, suffice it to say I've reproduced your issue
on my Win7 64bit box, and then resolved it by installing the PyWin32
modules.   It's probably a good idea to install this package anyway -- if
you're working on Windows the PyWin32 modules are very useful - they
basically wrap and makes available a shedload of Windows specific API's to
Python. (Many people working with Python on Windows almost automatically
would install this, it's also why i didn't run into this issue in the first
place as I already had PyWin32 installed prior to testing my suggestion.
Sorry.)

Anyway.  To download and install PyWin32, go here: http://ur.ly/vLwv

Presumably you want the AMD64 (64 bit) Py2.7 version.   Install it then try
your test again.

Fingers crossed. ;)

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


Re: [Tutor] Web Harvesting & AJAX/Javascript

2010-11-30 Thread Walter Prins
Hello Roy

On 29 November 2010 19:42, Roy Hinkelman  wrote:

> Researching this has led me to PAMIE and Selenium. PAMIE is giving me
> problems with permissions, and the discussion group appears to be fading
> away. I have not tried Selenium yet. Both open a browser instance, and PAMIE
> is quite slow, and I expect Selenium to be quite slow as well.
>
> How are you navigating around these Javascript based pages? Is there a
> library or plugin that I am missing?
>

I'm no expert in this area, however I have done some research in this
direction in the past, also to deal with sites that use Javascript
(obviously Python is very adept at interacting with sites that are plain
HTML by itself, e.g. there's lxml, BeautifulSoup & friends etc) and I remain
interested in this.

Anyway so then, here's my $0.02 for what it's worth.  Firstly, Selenium may
be an option, I briefly played with it quite some time ago, I don't know
PAMIE.

However, I suspect what you might rather want to look at is perhaps
something like the PyWebkitGTK (or PyWebkitQT) which leverages the webkit
browser engine.  (This kind of assumes you're on Linux... are you?)

Some hopefully relevant links:
http://webkit.org/
http://code.google.com/p/pywebkitgtk/
http://www.gnu.org/software/pythonwebkit/
http://www.pygtk.org/pygtkmozembed/
http://directfb.org/

Best wishes,

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


Re: [Tutor] print problem

2010-12-03 Thread Walter Prins
Please post the exact contents of "test_script_test.py", don't paraphrase,
don't abbreviate. A good place to post code snippets are here:
http://pastebin.com/

That said, I'll try to put down some of the troubleshooting thought process
you should be having.

Firstly, the error message is telling you that on line 14 of your module on
the line saying "newk = dat[mystartl:myfinish]", that "mystartl" is not
defined.

So then you should be asking yourself "how can it happen that the program
can get to this point and 'mystartl' not be set?".

Which should lead on to "OK, let's see where mystart is in fact being set,
and see if there's conditions attached to that which may explain the
behaviour".

Which should lead to you looking back in the code and spotting the lines
that says:
... if dat[i].startswith('BEGIN LINE'):
... mystartl = i

OK, so: "mystartl" is *only* set if dat[i].startswith('BEGIN LINE') is
false.

So then the implication would be that dat[i] doesn't start with 'BEGIN LINE'
when run from the prompt, so the next question would be why that is?

The implication would be that it wasn't read from the file.

So then implication is that the file "test" that your script reads is not
what you think it is when you run the file from the prompt.

HTH,

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


Re: [Tutor] Newline

2010-12-03 Thread Walter Prins
Hello Ava/Ashley

On 4 December 2010 01:47, Ashley Blackwell  wrote:

> Exactly what is a newline character?


Not all characters used to encode information are printable/displayable
characters like the letters in the alphabet or numerals or punctuation and
symbols.  There's several "special" characters that have special meanings
and represent other things.  A "newline character" is such a character.  It
is character 13 in the ASCII character set (which is a well known encoding
standard that define a mapping between bytes of data and characters.   See
here: http://www.asciitable.com/ )  It's meaning is "start a new line"
instead of encoding "a" or "z" or "#" or whatever.


> I keep reading the same section of the book and I'm just not really
> understanding. Here's the code that the book uses to explain the newline
> character:
>
> print("Here", end="  ")
> print("it is...")
>
> The book says that I can specify that a space be the final character
> printed instead of a newline. In the first print() statement I specify that
> a space be the final string printed. So the text "Here" appears but no
> newline character. The next print() statement prints the text "it is"..."
> right after the space following the final "e" in the "Here" text. You do it
> by passing a space to the end parameter of the print() function with the
> code end"  ".
>

So, what this is trying to explain is that by default Python appends a
newline character to the end of whatever it's been told to print.  This has
the effect of normally puttig successive print statements on successive
lines.  However, you can override this behaviour and tell Python to use
another character as its "end" character to append to whatever is printed,
by specifying the "end" parameter.   If you for example replace this with
space e.g. " " then as you can see when you execute the 2 print statements
they end up on one line, seperated by thace space, instead of being on 2
seperate lines.

Does that help?

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


Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-10 Thread Walter Prins
Hi Steven

On 10 December 2010 03:50, Steven D'Aprano  wrote:

> Some languages (Pascal comes to mind) doesn't have short-circuit behaviour
> at all.
>

Don't mean to nit pick, but in my experience it really depends on the
compiler implementation and which version of Pascal you're talking about.
Certainly, Borland's Turbo Pascal had and later Object Pascal (today called
Delphi) has to this day short-circuit evaluation as default behaviour,
although you can turn this off via a compiler switch if you want.(And as
an aside, according to wikipedia ISO Pascal actually also allows but does
not require support of short-circuit boolean evaluation.)  It really depends
on what your program does -- if your program contains functions with
side-effects (a bad idea, but if it does) then short-circuit evaluation will
probably break your code.  On the other hand, not having short-circuit
boolean expression evaluation can in most programming contexts be needlessly
inefficient.

Anyway, your general point is of course quite correct, so feel free to
ignore my ramblings...

Best,

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


Re: [Tutor] role playing game - help needed

2010-12-12 Thread Walter Prins
On 12 December 2010 19:16, David Hutto  wrote:

>  I recall you making a habit of being an
> asshole(pystats should ring a bell, thanks for giving me the credit
> for inspiration...bitch)
>

Rudeness objection.  Ad-hominem objection.

Come on, this is not kindergarten.  We all have our foibles, and although
I'd agree the tone around here occasionally leaves something to be desired,
you just lower yourself to the same level and make matters worse if you
resort to this type of name-calling.   Let's stick to objectively (as far as
possible) critiquing and considering the points raised.

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


Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-21 Thread Walter Prins
On 21 December 2010 14:11, Alan Gauld  wrote:

> But I don't understand how uncompressing a file before parsing it can
> be faster than parsing the original uncompressed file?
>

Because of IO overhead/benefits.  It's not so much that the parsing aspect
of it is faster of course (it is what it is), it's that the total time taken
to (read+decompress+parse) is faster than just (read+parse), because the
time to actually read the compressed data is less than the time it takes to
decompress that data into RAM.  Generally speaking, compared to your CPU and
memory, with respect to IO your disk is always going to be the culprit,
though of course it does depend on exactly how much data we're talking
about, how fast your CPU is, etc.

In general computing this is less of an issue nowadays than perhaps a few
years ago, and the gains can be as you say small, or sometimes not so small,
depending exactly how much data you've got, how highly compressed it's
become, how fast/efficient the decompresser is, how slow your I/O channel is
etc, but the point nevertheless stands.  Case in point, it's perhaps
interesting to note that this technique is used  regularly on the web in
general -- most web servers actually stream their HTML content as LZ
compressed data streams, since (as above) it's quicker to compress, stream,
decompress and parse than it is to just stream the data direct.  (And, of
course, thanks to zlib + urllib one can even use this feature from Python
should you wish to do so.)

Anyway, just my $0.02!

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


Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-21 Thread Walter Prins
On 21 December 2010 17:57, Alan Gauld  wrote:

>
> "Stefan Behnel"  wrote
>
>  But I don't understand how uncompressing a file before parsing it can
>>> be faster than parsing the original uncompressed file?
>>>
>>
>> I didn't say "uncompressing a file *before* parsing it". I meant
>> uncompressing the data *while* parsing it.
>>
>
> Ah, ok that can work, although it does add a layer of processing
> to identify compressed v uncompressed data, but if I/O is the
> bottleneck then it could give an advantage.
>

OK my apologies, I see my previous response was already circumscribed by
later emails (which I had not read yet.)  Feel free to ignore it. :)

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


Re: [Tutor] Java Virtual Machine Launcher Question

2010-12-28 Thread Walter Prins
I'm guessing this question has something to do with this:
http://isatab.sourceforge.net/validator.html

Which appears to be some sort of Java application that validates "isatab"
files, which appear to be related to mentioned magetab files.

I'm further guessing that you thought a .jar file (A Java program archive)
would be openable by WinRAR, since it can open .rar files?  If so, they are
utterly different things.  If not, then apologies and please excuse my
incorrect inferrence.

It's unclear to me how this question relates to Python though?  Are you
trying to implement reading/writing/validation of isatab files in Python or
something?

Many thanks,

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


Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Walter Prins
On 4 January 2011 00:47, Alex Hall  wrote:

> class parent(object):
>  def __init__(self, l=None):
>  if l is None: l=[]
>

Missing "self". Perhaps you meant:

class parent(object):
 def __init__(self, l=None):
   if l is None: self.l=[]
   else: self.l=l


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


Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Walter Prins
Sorry, my last post was too hasty.  You also had a problem calling super.
It should be like this:

class parent(object):
 def __init__(self, l=None):
   if l is None: self.l=[]
   else: self.l=l

class child(parent):
 def __init__(self, *args, **kwords):
   super(child, self).__init__(*args, **kwords)
   self.l.append(5)

c=child()
print c.l

Basically: In Python 2.x "super()" doesn't know what the current class is.
You have to tell it, as the first parameter.  If you tell it a lie, strange
things will happen.  That's basically what you did.  You called
super(parent,...) instead of super(child,...)

Have a good 2011... ;)

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


Re: [Tutor] subclass not inheriting attributes?

2011-01-03 Thread Walter Prins
On 4 January 2011 01:16, Vern Ceder  wrote:

> I believe you need to pass the object both to super() and to the method
> itself, as in:
>
> super(parent, self).__init__(self, *args, **kwords)
>
> See the example at
> http://docs.python.org/library/functions.html?highlight=super#super
>
> HTH,
>
> Vern
>
>
I've already pointed out that you're supposed to tell super() the *current*
class and Alex has already indicated that it now works for him?  Is there a
problem with everyone on the mailing list receving posts timeously?

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


Re: [Tutor] Parse MPL files

2011-01-08 Thread Walter Prins
On 7 January 2011 22:16, PyProg PyProg  wrote:

> Hi all,
>
> I'm looking for a way to parse MPL files (.MPL or .mpl extension).
> These files are contained in the tree of some cameras that support the
> AVCHD ... and some cameras filming with a stream mpeg-ts.
>

I've only been able to locate this:
http://forum.videohelp.com/threads/296805-Reading-AVCHD-Playlist-files-BDMV-Playlist-*-mpl

which links here:
http://eiman.tv/misc/flashdump.txt

... which *might* be relevant and somewhat helpful.

Hope that's of some use

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


Re: [Tutor] Ideas about global variables for accessing project's file

2011-01-12 Thread Walter Prins
Hi,

On 12 January 2011 13:11, Kann Vearasilp  wrote:

> Below is the structure of my project
>
> /src
> /src/modules/mod1
> /src/modules/mod2
> /src/data/file1
> /src/data/file2
>
>
> I wrote some codes in mod1 to access data in file1. And to read the file1,
> I am hard coding in the mod1, which is something like...
> open(blahblah/src/data/file1, "w")
> Now the problems arise when I share my code with other collaborators and
> the code is not working any more because his/her blahblah before /src is
> different.
>
> Is there a way to make a global variable for the project to make my life
> easier? Sometime like... PROJECT_PATH/src/modules/mod1 which PROJECT_PATH
> should work with every machines.
>

1.) You should be able to use relative paths, e.g. something like:
open("../data/file1", "w")
2.) You can set up configuration for your application to define where the
data files live.  See e.g. the "ConfigParser" module:
http://wiki.python.org/moin/ConfigParser

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


Re: [Tutor] How to plot graph?

2011-01-20 Thread Walter Prins
Hi Tee,

On 20 January 2011 03:48, tee chwee liong  wrote:

>  actually i just want to plot a simple x and y graph. any suggestion?
> how about using excel to plot? any sample code that i can follow to:
> 1) launch excel
> 2) read x-y from a text file
> 3) plot graph
>

Try this page:
http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/

Lots of example there which should circumscribe what you want to do.

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


Re: [Tutor] Telephone app

2011-01-22 Thread Walter Prins
Hi David,

On 22 January 2011 20:03, David Hutto  wrote:

> This is just a reach question. What modules would i want to use if i
> wanted to just send the signal, and receive the signal, other than
> maybe, signal. In other words please tone.dumb it down, and show a
> pseudo example.
>


I've read your question several times and don't really understand what
you're asking?  What signal are you trying to send and receive?  From the
subject I must guess you want to interact with the phone somehow, but I'm
not exactly sure what you're asking.  (You're right though, that the
"signal" module has nothing to do with telephones.)

On Windows, the standard way to interact with telephony systems is via the
TAPI interfaces  (
http://msdn.microsoft.com/en-us/library/ms734273%28v=vs.85%29.aspx) , which
I guess should be directly usable in Python via at least PyWin32 or some
other means.  It's also possible that a Python specific wrapper exists,
although a quick google hasn't turned up anything obvious.

 Hope that helps...

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


Re: [Tutor] Telephone app

2011-01-23 Thread Walter Prins
On 23 January 2011 21:04, David Hutto  wrote:

> So I have to receive the signal that the phone is ringing(then I'm
> assuming it sends the caller id info in between rings in some form)/or
> transmit a series of tones to them to connect.
>
> So I think my main question is what modules might be relevant to doing
> this? And should I be thinking of it any differently than a USB port
> which has 4 pins two data(+-), and two dc current(+-)?
>
>
I think you're thinking too low level, as alluded to by Alan this type of
stuff is done via a voice-modem that you can directly control (via serial
port) and get signals from e.g. using its command set.  A common standard
for about 3 decades has been the Hayes command set:
http://en.wikipedia.org/wiki/Hayes_command_set

As for control from Python - given that the modem would be present as a
serial (COM port) device in the system, I'd have thought that (at worst)
you'd be looking to use PySerial to interact with the modem.  There may also
be more targetted wrappers specifically wrapping modems (don't know, haven't
looked).  And as mentioned before, you can probably also use the more
abstract interface provided by the operating system (TAPI stuff).

And yes, USB is quite different from the POTS (Plain Old Telephone System).
Forget any ideas that they're anywhere the same thing.

Hope that helps.

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


Re: [Tutor] extracting text from word files (.doc, .docx) and pdf

2011-01-25 Thread Walter Prins
On 25 January 2011 21:52, Juan Jose Del Toro  wrote:

> Dear List;
>
> I am looking for a way to extract parts of a text from word (.doc,.docx)
> files as well as pdf; the idea is to walk through the whole directory tree
> and populate a csv file with an excerpt from each file.
> For PDF I found PyPdf ave found nothing to read
> doc, docx
>

http://www.google.com/search?q=python+read+ms+word+file&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a

which returns this:

http://stackoverflow.com/questions/125222/extracting-text-from-ms-word-files-in-python

Additionally -- docx are, IIRC, zipped XML, so you could probably just
uncompress it and scan the XML directly...

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


Re: [Tutor] Need help on Setup.py

2011-02-01 Thread Walter Prins
Hi Victor,

On 1 February 2011 07:38, Victor Binns  wrote:

>  I have been trying to add some of the extras with python such as pywin32
> and others.
>
> when i click on setup.py it does not work.
>
> I need help on the problem.
>
>
This is because setup.py is not intended to just be run without
paramters/arguments.  This is explained in the readme, which states:

"'setup.py' is a standard distutils build script.  You probably want to:

% setup.py install
or
% setup.py --help

As for Python itself, these extensions require MSVC7 for Python 2.4 and
later, otherwise MSVC6.  Some extensions require a recent "Platform SDK"
from Microsoft, and in general, the latest service packs should be
installed, but run 'setup.py' without any arguments to see
specific information about dependencies.  A vanilla MSVC installation should

be able to build most extensions and list any extensions that could not be
built due to missing libraries - if the build actually fails with your
configuration, please log a bug via
http://sourceforge.net/projects/pywin32.@
"

Notice, this implies that pywin32 includes C modules..., which means that to
install from pywin32 from sources you'll also need a C compiler (Microsoft
Visual Studio I guess.)  This is, I strongly suspect, not what you intended
at all, so for PyWin32 you really want to just download a Windows .exe
installer package and install that, as Alan suggested.

In general, if you're installing pure Python packages (e.g. no C modules),
"setup.py install" is a perfectly acceptable way to install such
packages/modules.  If there's native Windows intsaller packages available
that's also of course fine (and probably easier for Windows users due to
being more familiar.)

Regards,

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


Re: [Tutor] Higher-Order Function Examples

2011-02-14 Thread Walter Prins
2011/2/14 Rafael Durán Castañeda 

> Could we consider sorted as an high order function?
>
> sorted_list = sorted(list_strings, key = str.lower)
>
>
No because sorted() returns a list as a result.   A higher order function
produces another function as a result, or takes one or more functions as a
parameter.

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


Re: [Tutor] Higher-Order Function Examples

2011-02-14 Thread Walter Prins
2011/2/14 Rafael Durán Castañeda 

> In the example I gave:
>
>
> sorted_list = sorted(list_strings, key = str.lower)
>
> sorted takes str.lower as a parameter, doesn't it? So, it should be a high
> order function
>

My apologies! Yes, you are of course quite correct!  :)

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


Re: [Tutor] Convert string to long

2011-02-24 Thread Walter Prins
On 24 February 2011 11:50, tee chwee liong  wrote:

>  > int(s,16) for a hex string
> >
>
> great but the leading zeroes are being truncated.
>

You need to seperate the concept of display/formatting of some thing from
the actual thing/value being displayed.

Normally when we humans communicate numbers and or work with them, leaading
zero's are not used, so normally most computer systems and languages will
not display numbers with leading zeros by default.  It is therefore up to
you to *tell* the computer you want leading zeros in order for it to produce
them from the actual value being represented.

Furthermore you need to distinguish (as does the computer) between different
object types (namely strings and numbers) as they are different animals
which are handled differently by the computer.

A number, as already mentioned, will be by default not displayed with
leading zeros as that's normally how humans are used to seeing numbers.

A string however is a data structure that can contain arbitrary characters.
The computer therefore will generally just display a string with whatever is
in it (some exceptions apply for escape characters etc depending on context
etc. but ignore that for the moment.)

Now, a string may contain characters that happens to be the character
representation of number (with or without leading zeros) but yet to the
computer this remains a string and only a string, until you *explicitly*
tell it otherwise and explicitly convert it into an actual number object.
After you've done this of course, the computer will know that the thing now
being dealt with is in fact a number, and will therefore display/format the
number as it usually does (e.g. without leading zeros), again, unless you
tell it to display/format it otherwise.

So at the risk of belaboring the points: 1) Get a handle on the fact that
numbers and strings are different things, and that on the one hand you're
converting between them.  2) Get a handle on the fact that different things
can furthermore be displayed/formatted in a variety of different ways, and
there may be many ways to display or represent a given thing, which again is
up to *you* to control/specify.

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


Re: [Tutor] Help on Python Looping Please

2011-02-24 Thread Walter Prins
On 24 February 2011 14:52, pyhx0r  wrote:

> *Why do in my code, it loops to all values and not in Mark Pilgrim’s code?
> *
>
>
Because in Mark's code the loop is terminated by the return statement
(contained in the utility function approximate_size().)  In your code you've
removed the entire function including the return statement, consequently the
loop runs to completion.

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


Re: [Tutor] Help on Python Looping Please

2011-02-24 Thread Walter Prins
On 24 February 2011 16:22, Dave Angel  wrote:

>
> (Is there a reason you double-spaced all that code?  It makes it very hard
> to read, and quite difficult to quote, since I had to delete every other
> line.)
>

For what it's worth the code came out perfectly fine on my email reader
(GMail). (No double spacing, courier formatted, all in all pretty easy to
read. What email client are you using?)

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Walter Prins
On 26 February 2011 05:33, Corey Richardson  wrote:

> Aha, that explains why I didn't get any results. Each file got its own
> interpreter instance.
>

Not wanting to nit pick, but no: It's not that each *file* does has its own
interpreter instance, it's that every python instance that you start does
not automatically persist anything that gets created while it lives. In
other words, you can import many modules (files) into any given interpreter
instance, but whether or not the stuff gets persisted anywhere is a seperate
matter.

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Walter Prins
On 26 February 2011 05:33, Corey Richardson  wrote:

>
> I'm slightly concerned about performance when it comes to
> reading/writing to disk a lot when doing things like that, since if this
> thing ever needs to scale I want it to be able to do that.
>

I'd be tempted to say you should not be worrying about such performance
issues at this stage.  Remember what Knuth said, "... premature optimization
is the root of all evil"  Suffice it to say you can push rather large
amounts of disk I/O with Python, and you can always come up with creative
caching systems or whatever once you get that far along and it proves to be
a problem.

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Walter Prins
On 26 February 2011 11:06, Corey Richardson  wrote:

> I ran them like this:
> python use1.py
> python use2.py
> python plib.py
>
> Each file got its own instance of the interpreter.
>

Yes, but not because instances are intrinsically linked to seperate python
modules, which is what it sounds like you're saying.  In the above case you
*explicitly* started the 3 python instances seperately yourself from the
command line, giving each instance a file to run, which is why you got 3
seperate instances.  It's nothing to do with the fact that you have 3 files
as such.  (You'd have had 3 instances even if you ran the same file 3
times.)  If you e.g. ran "use1.py" which then imported or ran use2.py and
use3.py they'd all have used the same instance.  Similarly, if you'd opened
all 3 files in IDLE, and ran them with F5 in turn, they'd all have run in
the *same* interpreter instance.Perhaps you do understand and you've
expressed yourself poorly or I've just miinterpreted what you meant, I just
wanted to make sure you don't think that seperate files (modules) will by
some magic always have their own instances (which is not the case in
general.)

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Walter Prins
On 26 February 2011 11:10, Corey Richardson  wrote:

> On 02/26/2011 06:05 AM, Walter Prins wrote:
> > I'd be tempted to say you should not be worrying about such performance
> > issues at this stage.
>
> Indeed, but I can't have every piece of variable information being saved
> to disk and then read back again every time a player leaves or enters a
> room, that'd just be silly!
>

Sure.  I still think however that at this stage it's a much of a muchness.
Modern PC's and disk caching subsystems being what they are, you likely
won't really notice it either way until you're quite far along with this
project.  ;)  (I'm not suggesting you should be willfully stupid of course,
and the mere fact that you write the above indicates you're not, so there's
no problem!)


> Playing MUD's for a bit it gets annoying on a medium-size server when
> you have to wait more than 3 seconds just to get how much health you
> have after attacking some baddie. I won't be trying to pull every
> microsecond of efficiency out of this, but I would like it to be
> sensible and now waste time dawdling.
>

Sure.  It's of course an assumption that the delay you see is due to disk
I/O... (it may well be, but then again there's lots of possible reasons for
things being slow...)


>
> (And the full quote is "We should forget about *small* efficiencies, say
> about 97% of the time: premature optimization is the root of all evil."
> (emphasis added))
>

I know what the full quote is, I continue to be of the opinion that the
point it makes is relevant, it's not worth worrying too much about.  Pick a
strategy that works sufficiently, you can always refactor and improve when
needed.

Good luck,

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


Re: [Tutor] accessing another system's environment

2011-02-26 Thread Walter Prins
On 26 February 2011 04:26, Bill Allen  wrote:

> Yes, that's it exactly.:-)
>
> I administrate the workstations in our engineering environment and some of
> the major pieces of software we use are configured via the Windows system
> environment variables.  Being able to reach out to a PC and check or change
> those is handy, even important, in my situation.   I am trying to explore
> the possibility of managing these from a system I am using in a platform
> independent way and figure that I ought to be able to do this with Python.
> Perhaps there are third party Python modules I need to help accomplish this?
>

Are you intending changing *running processes* environment variables, or
merely update a given PC's configuration so that next time an app starts
they'll see the new settings?  (I'd guess the latter as even Windows itself
won't e.g. update running instances of cmd.exe's environment when you change
them after an instance of cmd.exe has started.)

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Walter Prins
On 26 February 2011 21:18, Justin Bonnell  wrote:

> --I tried to follow this using:
> /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
> which is the correct location of the hello.py file.
>

Try putting quotes around the full path. The problem is that the space
between "Python" and "2.7" makes the line look like 2 arguments, e.g.
 /jwbonnell/bin/Python
... and ...
2.7/Extras/Demo/tkinter/guido/hello.py

If you double quote the entire string like so:
"/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py"

By quoting the line you're telling the system not to interpret that space
and make it part of the argument to the Python interpreter.  (Aside: You
would need to quote the path also when using it with the "cd" command, as
the same problem will happen unless you quote it.)

The other thing I'd suggest is to just use IDLE which may be slightly easier
at this point.  In the main IDLE shell, click "File"->"Open", open the file
(it opens in its own window) then run it from there using e.g. F5.  The
output appears in the IDLE shell then.

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


Re: [Tutor] Saving information for my program

2011-03-21 Thread Walter Prins
On 21 March 2011 15:11, michael scott  wrote:

> I was thinking I have 2 options, which is save the information to a text
> file a write / read it in every session, but I have no idea how to do this
> with class attributes. I know how to do it for like a paragraph of text, but
> I have no idea how to do it with classes and their attributes.
>

If you know how to save text, then you should be able to write your own code
to store ("persist") your objects, shouldn't you?  Trying to do so might be
a good learning excercise... ;)

Anyway, I agree with Bob Gailer's advice, and I'd suggest you play around
with several options, learning as you go.  If you design your code
appropriately, you can even start now with e.g. a persistence layer that
uses Pickle (or your own home-brewn save/load code that uses ini file or
text file or whatever), and later move to an SQLite store or even another
relational database engine.

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


Re: [Tutor] script conversion windows -> linux error

2011-03-25 Thread Walter Prins
On 25 March 2011 18:26, Rance Hall  wrote:

> config_version =  config.get('versions','configver',0)
>
> This line fails under 3.2 Linux with the error message:
>
> TypeError:  get() takes exactly 3 positional arguments (4 given)
>
> What could the 4th argument be?  I only see three.
>
> This same code worked on python 3.1 under windows.
>
> What am I missing?
>

OK, off the top of my head and not having checked anything, here's me
thinking out loud:

Recall that all methods get one extra parameter, namely the instance
reference of the object that the method applies to/is being called on.

Regardless, the message is telling you that you're passing one more
parameter than expected.  This makes me think that the version of config
module that you're using is older than the one you used on Windows, and that
perhaps this older version had one less parameter, which is why it's
complaining about too many parameters.

As I say, that's just educated guesswork/inference, I've not checked whether
the above hypothesis holds water under examination...

Best wishes,

Walter

2) Consequently always adjust error messages, taking into account that the
real number of paramers passed to a method is always one more than the
"real" parameters.
3) Given that you're explicitly passing 3 parameters in the code, this means
that in reality 4 is passed, your 3 + the instance reference.
4) Since the error is that only 3 is expected (e.g. 2 + instance) this
implies that you're
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] script conversion windows -> linux error

2011-03-25 Thread Walter Prins
Ugh, please excuse my tardiness and ignore the numbered items below my
signature which I was intending to delete, I accidentally hit "end" before I
cleaned up the post... :red faced:
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to read remote text file?

2011-03-28 Thread Walter Prins
Hi

On 28 March 2011 11:53, Steven D'Aprano  wrote:

> There are some projects that have tried to reverse-engineer the format,
> like the xlrd package.
>

Yes, just to add, xlrd is the "reader" module, the Excel "writer" is xlwt,
available here: http://pypi.python.org/pypi/xlwt

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


Re: [Tutor] HELP

2011-04-02 Thread Walter Prins
2011/4/2 ISAAC Ramírez Solano 

>
> Hi... My name is Isaac, I need some help to programm in python, I know some
> things that are really basic like lists and recursivity and with that we
> shoul create an GPS with a global variable, but what I'm trying to do is to
> make a function that could call the global variable
>
>
Read this page:
http://www.saltycrane.com/blog/2008/01/python-variable-scope-notes/

Then come back if you have further questions.

Regards

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


Re: [Tutor] Tutor Digest, Vol 86, Issue 12

2011-04-03 Thread Walter Prins
Hello,

2011/4/3 Mateusz Koryciński 

>
> (2) You have a *mess* of unreadable variable names. You have:
>>
>> w.steps w.x w.y w.world data.c data.n data.e data.s data.w data.cc
>>
>> (yes, you have data.c AND data.cc!!!) plus loop variables z i j and r,
>> and z is never used! How is anyone supposed to understand what this
>> does? Even if you solve this problem *today*, in a week you will have
>> forgotten what the code does and you won't understand it.
>>
>>
> It's an objects from another classes. Variable z is used because there is a
> need to provide number of steps to execute by user. Variable c mean central
> cell in array whe are considering right now, other one is neighbours but cc,
> cc means new state (couse basing on central cell and its neighbors we want
> to change value to cc).
>

I think the point that was being made was that all this (and the other
explanations you gave) should be in or circumscribed by your source code,
and that you should try to use longer/more meaningful variable names.  It
wasn't specifically a request for you to explain all of these things here on
the email list, although that might be helpful going forward.  Nevertheless
you still need to make these things part of and as obvious as possible from
reading your source code.  It should always be the definitive reference.
IMHO source which has to be substantially explained outside of itself should
be improved/clarified/documented/commented inside the source until external
explanations are largely unneccesary and the code is as far as practicable
self-documenting.

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


Re: [Tutor] Python 3.2 Install Not Responding To Python Command!!

2011-04-09 Thread Walter Prins
On 9 April 2011 17:44, Nevins Duret  wrote:

> Compiling with Ubuntu
>
> # get required packages for buildsudo apt-get install build-essential 
> libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev 
> libsqlite3-dev tk-dev
>  # get sourcewget http://www.python.org/ftp/python/3.2/Python-3.2.tgz && tar 
> -xvf Python-3.2.tgz
>  # make install
> ./configuremakesudo make altinstall
>  # make 3.2 the default python system wide (number 1 at the end stays 
> there)sudo update-alternatives --install /usr/bin/python python opt/py32/bin 1
>  # ensure various versions of python play nice with each othersudo 
> update-alternatives --config python
>
>
> Again I really appreciate your help, getting over this hurdle would help me 
> be confident in what goes on under the hood.
> At this point, it seems that I will need instructions on how to remove 
> python3.2 in order to get a reattempt at installing it
> properly.
>
>
>
OK... It's usually preferable if at all possible to install things using the
system's package manager -- is there any particular reason that you must use
Python 3.2 and can't install Python 3.1.2, which is available in the
repositories? It may be installed by simply doing:

sudo apt-get install python3-all

As for fixing/undoing any problems in your system -- I'm reluctant to try
and fix that via this list and without more information.  I'd therefore
suggest asking on the Ubuntu community forums programming sub-forum.
http://ubuntuforums.org/forumdisplay.php?f=310

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


Re: [Tutor] Python 3.2 Install Not Responding To Python Command!!

2011-04-10 Thread Walter Prins
On 9 April 2011 19:45, Nevins Duret  wrote:

> I can't thank you enough for your help.  Yes, I usually use the Synaptic
> Package Manager, however in this case, Python version 3.2 is not on the
> Synaptic package Manager.  This is why I chose to build it from source.  As
> far as what I think is causing this when I go in the
>

No problem.


> Terminal and type:
> sudo update-alternatives --install /usr/bin/python/python3.2 python
> /opt/py32/bin/python3.2 1
>
> I get this as an error message:
>
> update-alternatives: renaming python link from /usr/bin/python to
> /usr/bin/python/python3.2.
> update-alternatives: warning: forcing reinstallation of alternative
> /opt/py32/bin because link group python is broken.
> update-alternatives: error: unable to make
> /usr/bin/python/python3.2.dpkg-tmp a symlink to /etc/alternatives/python: No
> such file or directory
>

I would expect that "update-alternatives" would have trouble (on the first
line) because /usr/bin/python is not a link anymore (but instead a folder)
based on your previous posts.

So, please go and inspect the /usr/bin/python folder and see what if
anything's inside.  If it's not empty you need to see what is in fact in it
and hopefully get rid of it or move it out of the way. Once it's empty, then
just delete the /usr/bin/python folder (you'll have to be root or use
"sudo") and afterwards either recreate a link to the default python
interpreter and/or try the update-alternatives command again. (To manually
restore the default python link, first execute "which python2.6" which
should output "/usr/bin/python2.6", then execute "sudo ln -s
/usr/bin/python2.6 /usr/bin/python" which should restore the link to the
default python.  After doing this "update-alternatives" should have less
trouble redirecting the /usr/bin/python link.

I however want to reiterate that your problems, especially fixing your OS,
will be better dealt with on the Ubuntu community forums.

Rohan, thanks for posting about that PPA, wasn't aware of it!

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


Re: [Tutor] voluntary work :p:

2011-04-26 Thread Walter Prins
On 26 April 2011 04:59, Wolf Halton  wrote:

> I didn't get anything out of pythonchallenge.  All seems static.  Do you
> need flash or something to make the magic happen?
>
>
To add to what the others have said and explain the "flow" a bit more:  Each
challenge is a puzzle, with hints present in various places, either in the
displayed image and/or text, sometimes in the page source, sometimes hidden
inside an image or a file that you must download etc, and so on.

The general goal for solving each puzzle is to find the next puzzle's
solution URL and the next puzzle URL by modifying the page URL of the
current puzzle based on your detective work on the current puzzle.  In
several instances (especially in the beginning) it's actually possible to
solve a puzzle without using Python, but obviously the idea is really to
solve or perform whatever calculations are required using Python, and
thereby in the process learn something about Python as you go.

Now, the very first puzzle presents you with a number, 2^38, and a hint "Try
to change the URL address".  Now, with a bit of research you'll find that
Python's way to expressing exponentiation is with the ** operator.  Thus,
one might as a first try, attempt changing the URL to simply that, e.g.:
http://www.pythonchallenge.com/pc/def/2**38.html

Attempting that, takes you to a page that says: "give the answer, not the
question." ... Hmmm

OK.  So that should lead you to the conclusion that you need to actually
calculate the answer to 2^38, and then try that in the URL instead... Now
after a bit of reading you should find out about the interactive aspects of
the Python interpreter and that you can use it as a calculator, and that you
can calculate the answer by simply typing 2**38 into the Python
interpreter.  Doing all that then teaches you something about the Python
interpreter, and the fact that Python copes easily with very large numbers,
which in many other languages would be problematic.

And so it goes.  You'll quickly get to places where you e.g. have to
interact with the website quite a number of times to figure out what the
next puzzle URL should be, and thereby be pushed to learn about urllib and
Python's wonderful web modules in order to automate the interaction, places
where you have to do some relatively involved (if you tried to do the same
in other languages) text processing in order to get the answer and so on.

Every puzzle pushes you to learn about a specific aspect of Python, and
impresses upon you (especially if you have any prior programming experience)
just how elegant and powerful Python really is.  As an aside, The Python
Challenge was one of the things that originally impressed on me just how
good and useful a language Python really is, and how wide the variety of
contexts are where it can be usefully applied.

Best regards,

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


Re: [Tutor] Gtk - relational data display and edit

2011-04-26 Thread Walter Prins
On 26 April 2011 16:34,  wrote:

> Hi,
>
> I am reading in data from a csv file which will be in a format like this
>
> User1, attrib1, attrib2
> User2, attrib1, attrib2
> Etc.
>

Why would the data be in this format?  Are you defining it?  Reason I ask is
that, relationally speaking, (e.g. database design-wise) this is a
denormalised representation and you'd do better to store a single attribute
per record.  E.g. have entities, User, Attrib, and have relationship table
User_Attrib that contains only user, attrib pairs.  But, maybe such ideas
are overkill for your app.



> And need to display this in a window. My initial thought was to use
> gtk.Entry widgets because I will need to edit this data, but I don't think
> this will work as I will also need to read the data back, in relation to the
> user column, e.g I will have something like
>
> [Psuedocode]
> For I in entries:
>A = usercolumn
>B = attrib1column
>C = attrib2column
>
>Somefunction(A,B,C)
> [/psuedocode]
>
> I don't think I could use this method with entry boxes as I have no idea
> how many entries there will be (column length will be fixed) so I can't
> create the entry widgets beforehand
>
> Anyone have any suggestions?
>

Well if you can count the number of entries on reading the file (whatever
the shape of the file) then in principle you can dynamically create the
correct number of entry boxes on the fly.  Of course, if you store one
attribe per record, then counting the number of attributes (records) for a
given user becomes quite easy of course. But even if you don't do this, and
you have the file structure you described, you can code reader code that
would internally store the attributes and the number of attributes for each
user, enabling you to write code to create the UI with the appropriate
number of entry widgets.

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


Re: [Tutor] How to compile source code in debian

2011-05-09 Thread Walter Prins
Hello,

On 9 May 2011 14:04, Ganesh Kumar  wrote:

> Hi Gurus,
>
> I want compile ubuntu software centre source code from debian how to
> compile...please help me..
> I downloaded all file contents have python file ..
>
> https://launchpad.net/ubuntu/maverick/+source/software-center/3.0.4
>
>

Python is not a compiled language (in the traditional sense.)  So you can go
ahead and edit the python sources directly, run the app etc, and/or run the
setup.py file as normal to install the application system wide. (E.g.
"python setup.py install" etc. If that doesn't make sense then I'd say you
need to become more familiar with the Python "lay of the lands". Actually
offhand I'm not sure how this will interact with/affect the default
software-center installed on Ubuntu, but suffice it to say once you've built
up enough familiarity with Python and Ubuntu you'll be able to answer such
uncertainties easily yourself by doing a few experiments... )

See how you go, and if you're still stuck post back and we'll try to help.
But be specific please, say what you've tried, what you expected, and what
you actually got.  Post the full text of any error messages you get.

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


Re: [Tutor] Python assignment

2011-05-09 Thread Walter Prins
Hello Matthew,

On 9 May 2011 23:42, Matthew Rezaei  wrote:

>   Hi There,
>
>
>
> I am hoping you can help me!
>
>
>
> I have a python assignment and I need help regarding it, is there anyone
> that can  help me out with it?
>

Yes.  We won't do the assignment for you, but if you try to solve it and get
stuck then we'll try to provide hints to get you unstuck. Remember to
include full error messages and actual source code if you get stuck.  Don't
paraphrase code, don't shorten error messages.  Don't make assumptions about
what is wrong and then send us input based on those assumptions.  Do send as
much information as possible. Remember to "Reply-all" to ensure responses do
go to the list as well.

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


Re: [Tutor] create an xls file using data from a txt file

2011-05-11 Thread Walter Prins
On 11 May 2011 03:57, tax botsis  wrote:

> I tried to work that out with xlwt but couldn't. Actually, I started
> working on the following script but I couldn't even split the line for
> further processing:
>
>
OK, I've thrown together a quick sample demonstrating all the concepts you
need (obviously you need to take from this what is relevant to you):

import csv
import xlwt
import os
import sys

# Look for input file in same location as script file:
inputfilename = os.path.join(os.path.dirname(sys.argv[0]),
'tabdelimited.txt')
# Strip off the path
basefilename = os.path.basename(inputfilename)
# Strip off the extension
basefilename_noext = os.path.splitext(basefilename)[0]
# Get the path of the input file as the target output path
targetoutputpath = os.path.dirname(inputfilename)
# Generate the output filename
outputfilename =  os.path.join(targetoutputpath, basefilename_noext+'.xls')

# Create a workbook object
workbook = xlwt.Workbook()
# Add a sheet object
worksheet = workbook.add_sheet(basefilename_noext, cell_overwrite_ok=True)

# Get a CSV reader object set up for reading the input file with tab
delimiters
datareader = csv.reader(open(inputfilename, 'rb'),
delimiter='\t', quotechar='"')

# Process the file and output to Excel sheet
for rowno, row in enumerate(datareader):
for colno, colitem in enumerate(row):
worksheet.write(rowno, colno, colitem)

# Write the output file.
workbook.save(outputfilename)

# Open it via the operating system (will only work on Windows)
# On Linux/Unix you would use subprocess.Popen(['xdg-open', filename])
os.startfile(outputfilename)


The code is also available at the following URL in case the formatting gets
eaten by the mail system: http://pastebin.com/APpM7EPf

Regards

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


Re: [Tutor] create an xls file using data from a txt file

2011-05-11 Thread Walter Prins
On 11 May 2011 14:34, tee chwee liong  wrote:

>  hi all,
>
> thanks for this sharing. when i copy and run this code, i got this error:
>
> Traceback (most recent call last):
>   File "C:/Python25/myscript/excel/sampleexcel.py", line 1, in 
> import csv
>   File "C:/Python25/myscript/excel\csv.py", line 3, in 
> w=csv.writer(open('output.csv','w'))
> AttributeError: 'module' object has no attribute 'writer'
>
>
Well, reading the error message, it's saying that module "csv", coming from
file "C:/Python25/myscript/excel\
csv.py" has no member "writer".  So, it seems you've called your test script
(module) "csv" which effecitvely hid the standard python "csv" module.

Try renaming your script file to something else ('testcsv.py' maybe) so its
name doesn't conflict with the standard "csv" module and try again.

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


Re: [Tutor] Just Joined!

2011-05-12 Thread Walter Prins
On 12 May 2011 12:34, Alex Smith  wrote:

> Hi All,
>
> I just joined this list and am really new to python. I have an assignment
> to create a function with (a_string, width) which returns the a_string with
> all the lower case characters changed to upper case characters and vice
> versa and centered; was wondering if someone could point me in the right
> direction. I am not just asking for the answer but just need a few tips to
> get started. So far I do know I should use the dir(str)
> and do not quite understand what the "width" option is used for
>
> I think you're missing the point about the suggestion to use dir() -- as
per the help you yourself retrieved, dir returns "an alphabetized list of
names comprising (some of) the attributes of the given object, and of
attributes reachable from it..."  The suggestion to do dir(str) was intended
as a way to learn about how string objects work in Python, not that it
should be used directly in the source code of your solution.

For example, "dir(str)" lists an interesting attribute (in this case a
method) called "swapcase"... now investigating this by doing
"help(str.swapcase)" you get:
>>> help(str.swapcase)
Help on method_descriptor:

swapcase(...)
S.swapcase() -> string

Return a copy of the string S with uppercase characters
converted to lowercase and vice versa.

Sounds relevant to your goals. ;)

As for the "width" question, think about the requirement to "center" the
string.  Centered with reference to what?  How are you going to center
something if you don't know how wide the thing you're centering on, is?

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


Re: [Tutor] RuntimeError: file does not exist

2011-05-18 Thread Walter Prins
On 18 May 2011 15:45, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

> Hello Alan!!
> Can you please tell me, how to rebuild my path? I've tried it, but I didn't
> succed =(
>
> Always post the code you tried, and the full error message you received,
otherwise you make it unneccesarily hard for us to try and help you (in
which case many people might not bother to try.)

Thanks,

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


  1   2   3   4   5   >