- Original Message -
From: "Hans Fangohr" <[EMAIL PROTECTED]>
To:
Sent: Saturday, December 15, 2007 1:43 AM
Subject: [Tutor] python logging module: two handlers writing to the
samefile - okay?
> I have an example program (test.py) and the logging configuration file
> (log.conf) attache
> "earlylight publishing" <[EMAIL PROTECTED]> wrote
>
>>I don't know if this'll help or not but I just learned about this:
>>
>> file = raw_input(info).lower
>
> file = raw_input(prompt).lower() # note the parens!
>
>> The .lower is supposed to convert any input to lower case.
>
> It will ind
>
> Hey i have created a program that turns a string into a binary one. But
> when i began to test the program it turned out that it could not handle
> some special characters (e.g ÆØÅ). Could someone please help me?
These special characters have different values than those you have put into
yo
> Below, "student_seats" is a list of the class "student".
>
> Why does this code set every student.row to zero when there is only one
> student in the list with row > 5?
> It still sets them all to zero if I change the test to ">200" when there
> are
> no student.rows > 200.
> But if I change the
> Sorry I wasn't quite sure how to explain it it's a vector class i've
> written
> myself.
> I've worked it out now, I was using a vector as part of a quaternion and
> wanted to
> be able to pass a vector or individual numbers so it seemed the easiest
> way
> to be
> able to use the *sequence syn
It is helpful for GUI applications because of what it says about halfway
down the page, within __init__ you can bind certain messages to methods of
the class.
I would not say that it is recommended persé but I'm sure that there are
those out there that cannot write a program without putting it
- Original Message -
From: "dave selby" <[EMAIL PROTECTED]>
To: "Python Tutor"
Sent: Friday, December 21, 2007 12:03 PM
Subject: [Tutor] Cant write new line at end of file append
> Hi all,
>
> I need to write a newline at the end of a string I am appending to a
> file. I tried ...
>
>
>I did this and got this string :-
>
> "i hope you didnt translate it by hand. thats what computers are for.
> doing it in by hand is inefficient and that's why this text is so long.
> using string.maketrans() is recommended. now apply on the url"
> Is that the answer because it does not solve th
>I need to pull the highligted data from a similar file and can't seem to
>get
> my script to work:
>
> Script:
> import re
> infile = open("filter.txt","r")
> outfile = open("out.txt","w")
> patt = re.compile(r"~02([\d{10}])")
You have to allow for the characters at the beginning and end too.
Tr
>I am wondering if there is a good tutorial on Py2Exe and its functions?
> I have not been able to find one. I have samples but that is not good
> enough. It would be nice to have something explain all the functions for
> including directories, modules and all that stuff when making an
> execu
Ctrl+c will issue a KeyboardInterrupt which breaks out of programs such as
the one you described. (The only situation it doesn't is when the program
catches that exception. You won't see that 'til you get your sea legs ;-)
___
Tutor maillist - Tutor
Callbacks are where you send python (or a library) a function which it can
call(back). They are usually used to make things a little more generic.
Here's a (trying to make it simple) example.
example.py ###
# These first three are callback functions (nothing special
# is needed
eval will seriously limit you in this instance because eval only works on
expressions, not statements. (Assignment won't work, for example). You can
use exec though. (in which case, you wouldn't necessarily want a result
back)
just fyi
> text =my_get_pythoncommand() # text is the line of tex
Try the .add_command(...) method.
> Hello list!
>
> I was wondering if any of you could help me with this:
>
> I've got a small GUI connected to a SQLite DB. My OptionMenu pulls a
> category list from the DB, and there's a field to add a new Category if
> you
> need to. Now, I'd like the have th
> This~~ works, but may be a little inefficient. Especially the double
> addr.strip() here. Given, it doesn't really matter, but I like even better
> Perhaps a use of sets here... particularly intersection somehow...
Whoops, I'm not versed in sets (blush) I meant difference_update
_
After quickly looking over the code, I find it has a good foundation, it
seems to have been designed very solidly. I haven't looked very closely, but
if the messages are mostly alike with just one or two slight differences,
you might consider dynamically creating the messages (from a customer li
Cool! Code! (gullom voice - we must look at code, yesss)
> Hi there.
>
> What this section area does is takes a data file that is comma separated
> and
> imports - there is a unique ID in the first field and a code in the second
> field that corresponds to a certain section of information. Wh
I assume you realize that jpeg is a lossy format and that consecutively
resizing the same image will no doubt end poorly in image quality.
Also, I assume that you have a better understanding of the NEAREST and
BICUBIC options than I do because you are apparently comparing them. I do
know that thos
> Hi
>
> I was trying to learn about classes in Python and have been playing
> around but I am having a problem with the deepcopy function. I want to
> have a function that returns a clean copy of an object that you can
> change without it changing the original, but no matter what I do the
> origin
> Tiger12506 wrote:
>
>> Ouch. Usually in OOP, one never puts any user interaction into a class.
>
> That seems a bit strongly put to me. Generally user interaction should be
> separated from functional classes but you might have a class to help with
> command line interact
I like this.
class Counter:
def __init__(self):
self.score = 0
def incr(x, y):
self.score += 2*x+3*y
class Board:
def __init__(self):
self.counter = Counter()
self.curcoords = (0,0)
def update(self)
self.counter.incr(*self.curcoords)
Whatever OOP term is used to d
> Thanks Tiger12506!
>
> This has helped me understand the function(*tuple) syntax, as well as
> providing me with a concrete example.
>
> James
Cool. ;-)
Here's another, totally unrelated to counters and boards.
Kinda the opposite use of the * syntax I used earlier.
def
hould give an appropriate representation. The built-in string object does
the equivalent of
def __str__(self):
return self
def __repr__(self):
return "'%s'" % self #Notice this will give extra single quotes
around string
No, you will not interfere with the internal representatio
> hi
>
> i am developing a GUI application using TKINTER
>
> i want to open a file from the askopenfile(which is a tkFileDialog) using
> OS.SYSTEM.
>
> i have already created the file open dilog using
> tkFileDialog.askopenfile(parent=root,mode='rb',title='choose a file')
> Now i want to open a fil
> WindowsError: [Errno 193] %1 is not a valid Win32 application
This line says that %1 is not a valid application. Windows uses %1 to mean
the first argument on the command line to the program. Without seeing any
code, it would be difficult to tell where this is being introduced, but the
explan
I would always use the os functions to find the basename, but
You could exploit the fact that Windows considers the extension to be
whatever is after the last "." character.
fn = fn[:fn.rfind(".")]
>> > What I found is this:
>> > import os
>> > myfile_name_with_path = 'path/to/my/testfile.txt'
>
> Hey There Everyone,
>
> I'm following an example in a book and I can't find the error that's
> preventing this program from running. It's just an example of how to get
> a sprite moving. The images are all in the right folder. I can run the
> program and get a stationary sprite to appear.
[Background from Alan]
> If some other factor were to determine its behhaviour more
> closely - such as determining whether the Pizza was within
> the coordinate boundaries or in collision with another Pizza
> then that could be implemented via a message protocol.
> Thus the context object should r
Try regular expressions in the re module. This should make this code below
much much simpler. Downside is you have to learn a slightly different
syntax. Upside is - regular expressions are very powerful.
> Last week someone had an issue with raw_input() and how to get input for
> a number. So
> Of course I know and use reg. exps., the point of the function is not to
> validate input but to force the proper input.
So? Are you going to try to tell me that you can force particular input
without actually determining if its valid or not first? ;-)
Just a thought.
___
>
> class Task(object):
> def __init__(self, cargo, children=[]):
> self.cargo = cargo
> self.children = children
>
> def __str__(self):
> s = '\t'.join(self.cargo)
> return s
>
> def add_child(self,child):
> self.children = self.children + [child]
This is an excellent start.
self.children = self
Many email clients encode attachments in base-64. I think there are standard
modules in python which should be able to decode this.
> Hi
>
> I made a small python program at home and tried to send by email
> attachments
> to my studymates.
> The attachment however shows up as a strange text
>
>
>def recursive_print(self, level=0):
>print "\t"*level + self.cargo
>for x in self.children:
> recursive_print(x,level+1)
Whoops. should be
for x in self.children:
x.recursive_print(level+1)
___
Tutor maillist - Tutor@
>I aam writing some software which calls for some unreadable code in
> it to let me secretly set a registration key- it is to be shareware.
>
> I know this can be done, but have not the foggiest clue of how todo it.
> Any links, articles, pointers?
This is impossible to do completely, and whil
Just a thought~
The built-in id() function can be useful in helping to sort out stuff.
Returns a unique identifier for each object created so you can test whether
a different name is a different object or just a different name for the same
object. (This is what the 'is' operator does... Note:
> up to a thousand (not tested)
>
> words = {0:'zero', 1:'one', 2:'two', 3:'three', ... , 10:'ten',
> 11:'eleven', 12:'twelve', ..., 19:'nineteen',
> 20:'twenty', , 90:'ninety', 100:'one hundred' }
> def digitToString(n) :
>try :
>retStr = words[n]
>except KeyError :
>
> This could be written much more efficiently. It can be done with only
> these
> lists~
> ones =
> ['zero','one','two','three','four','five','six','seven','eight','nine']
> teens =
> ['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
What is it
> Isn't dictionary access faster than list access? Why are three lists
> 'much more efficient'?
Oh no, no, no. Dictionaries are faster when you are *searching through* for
a particular value. If you already know the index of the item in the list,
lists are much faster.
Dictionaries are hash ba
> Something like this happens with Pygame and IDLE. In Windows if you
> right click on a Python file and choose the "Edit with IDLE" option IDLE
> is started with a single process. If the program is run and it does its
> own windowing then it conflicts with Tkinter, used by IDLE. Start IDLE
> Nope, if you read the code you'll see the only mapping done is up to 20
> and then by tens up to 100, that's all.
> The same code could be used with a list, you'd only have to change the
> exception name.
I see. There were "..." in between each of the tens entries which I took to
mean that "big
>Hi
>i have been fooling around in python a bit and looked at a couple of
>tutorials, but something i >wonder about: is it posible to make python make
>an output in a windows "tekstbox" for >instance to make several adjustments
>to my network settings at once, by running a python >program
>and i
>> I've had little experience with dos. I believe I should use the
>> COMPACT, and then the MOVE dos command... Would
>> it go something like this?
>
> You could use these but you'd be better just using Python
> to do it via the shutil and os modules and avoid the DOS
> commands completely IMHO.
> Hello there all.
>
> I have a need to make a hi byte and lo byte out of a number.
>
> so, lets say i have a number 300, and need this number to be
> represented in two bytes, how do i go about that?
First question. Why would you need to do this in python? Second question. If
you could do that,
> Hello everyone,
>I am tryin to use the imagechop module but i am not able to
> implement it successfully. I want to compare two images and give the
> resultant of the image using difference module. i am tryin to save the
> resultant image. But i am getting some wierd error. It gives error
> "muhamed niyas" <[EMAIL PROTECTED]> wrote
>
>> Also i set 'C:\Program Files\OpenOffice.org 2.0\program' in PATH
>> evvironment
>> variable.
>
> Close but not quite.
> You need to set the module folder in your PYTHONPATH environment
> variable.
>
> PATH is where the python interpreter lives
>
> Is it possible to traverse say python lists via http://
>
> say there is a list in the memory
>
> can we traverse the list using list/next list/prev list/first list/last
>
> is there a pythonic library to do that?
>
> thanks
That's a very unlikely request. There are a few ways to interpret this
>> I probably won't need to start writing classes but I really want to
>> finish the book before I start coding something.
One of the greatest mistakes of my life was to completely finish a
programming book before I started coding something. It is why I cannot write
a Visual Basic program to thi
Some suggestions throughout
> def runThrough():
>walk = os.walk("/media/sda1/Documents/Pictures/2007") #location of the
> pics I want to use
>count = 0
>for root, dirs, files in walk:
>try:
>for x in files:
>if x.lower().find(".jpg")> -1: #If it's a
I'll throw in a couple of ideas, but I won't pretend to be an expert. ;-)
>I have written what i see as a pretty decent script to resolve this
> question:
>
> Write an improved version of the Chaos program from Chapter 1 that allows
> a
> user to input two initial
> values and the number of iter
There's a couple of errors in here that no one has addressed yet because the
question was geared towards programming style... So now I will address them.
Or undress them, I suppose. ;-)
> #!/user/bin/python
> """
>>From the testing laboratory of:
> b h a a l u u at g m a i l dot c o m
> 2008-02-
> This is something that one can only gain from experience?
> I really had to struggle to get the Light class to work at all.
> I have no idea how many times I started over. But I do feel
> that I am starting to learn some of this stuff.
This surprises me... I guess it does take experience. What i
It's dangerous posting something like this on a python website. ;-)
It has definite strengths over python, it seems, and some things I do not
like.
Particularly interesting is the compilation directly to exe. Damn. I'm am
seriously impressed with that. Cobra appears too new to learn and switch t
> There is nothing like growing a program to the point where you don't
> know how it works or how to change it to make you appreciate good design
Amen. I was recently fighting with an example of a multi-client, simple
server that I wanted to translate into assembly. Not only was the code
unreada
I wish to warn you that I've never done anything like this before, but I
have a couple of thoughts here. First thought is, network games tend to be
slow because sending state information to everyone with enough frames per
second to make it decent game play is a lot of information to send... So t
>>> list = []
> >>> total = 0
> >>> if total > 0:
> ... x = {'id': 'name', 'link': 'XX'}
> ... list.append(x)
> ... else:
> ... y = {'id': 'name', 'link': 'YY'}
> ... list.append(y)
> ...
>
Yeah.
list = []
x = {'id':'name'}
if total > 0:
x['link'] = 'XX'
else:
x['link'] = 'Y
> "bhaaluu" <[EMAIL PROTECTED]> wrote
>
>> States, getters-setters, direct access...
>> I'm still in toilet-training here/ 8^D
>> Can you provide some simple examples that
>> illustrate exactly what and why there is any
>> contention at all?
One clear example I can think of that shows the view
>> This is all fine and dandy, but the video game is pretty worthless unless
>> it
>> can show us what the score is. There are two ways to go about this. A)
>> Give
>> the video game a display which it updates, or B) Tear open the case of
>> the
>> video game and look at the actual gears that in
> I'm having issues when I test my software on XP, but not Linux. When I
> run the progam it fails after running for a while but not at exactly
> the same point each time. It fails in one of two ways, the user
> interface either completely disappears, or gives a OS error message
> unhanded exceptio
> Hmm. Not to me. The second version couples the game state with the
> display. I would rather have
True...
> This is an example of Model-View-Controller architecture (google it).
> Notice that the Game and Display are now reusable (maybe there are both
> GUI and text interfaces to the game, f
> while 1 < 2:
while 1:
or
while True:
is more common
>x = raw_input()
raw_input() always return a string, no matter what you type in.
>if type(x) != int or x == 11:
type(x) is always
x can never be 11, but can possibly be '11'. (Notice quotes indicating
string instead of integer)
If
> Now I'm curious.
>
> MVC is one of the oldest, best established and well proven design
> patterns going. It first appeared in Smalltalk in the late 1970's and
> has been copied in almost every GUI and Web framework ever since.
> I've used it on virtually(*) every GUI I've ever built(**) to the
>
> infile$ = "ad.txt"
> outfile$ = "ad.csv"
> infile=sys.argv[1]
> outfile=sys.argv[1]+".csv"
And these will give two different results. The QBasic version says
"ad.txt"
"ad.csv"
whereas the python version will give
"ad.txt"
"ad.txt.csv"
so you need to say
infile = sys.argv[1]
outfile = sys.arg
> And here is my I got work for me in Python.
>
> ===
> ===
> import sys
> infile=sys.argv[1]
> outfile=sys.argv[1]+".csv"
>
> f1=open(infile)
> f2=open(outfile, 'w')
>
> s2=""
>
> for line in f1:
> s=line.strip()
> if s=="":
> continue
> elif s==".block":
> continue
> elif s==".report":
> continue
Similar to the TerminateProcess function in win32api, there is the
TerminateThread function which you can use if you know the handle of the
thread, but it seems that you can only get the thread handle if you are
calling from that thread, or if you were the one who created it (and saved
the retu
> As I understand it python is not a strongly typed language so no
> declaration
> of variables is necessary. My question is this:
>
> If I use a variable in a program that stores certain numbers and I'm
> porting
> it to say ... java where I must first declare the variables before I use
> them
> I was thinking more or less along the same lines, but
> - you don't need the copy()
Hehehe, did you try it Kent?
> - locals is a dict mapping names to values, so something like
> for name, value in locals().iteritems():
> print "varname: %s type: %s" (name,type(value))
And this returns
> As far as I can see, these routines give me the results
> I'm looking for. I get a distribution of four negative numbers,
> four positive integers in the range 10 to 110, and nothing
> is placed in room 6 or room 11:
I'll throw a couple of thoughts out there since I know that you appreciate
to
> If you literally want print statements to appear in a dialog then no,
> you can't do that (so far as I know!). But if you want the Tkinter
Alan??? Redirect standard output. It doesn't have to be a file object. It
can be any object with a write method.
_
This is bill's method written out in code which is the python you seek,
young warrior!
inname = 'inputfile'
outname = 'outfile'
infile = open(inname,'r')
outfile = open(outname,'w')
infile.readline()
line = infile.readline()
while line != "":
outfile.write(line)
infile.close()
outfile.close()
Python lists are mutable. All mutable objects will behave in the fashion you
described, whereas immutable objects -- tuples, integer, floats, etc. --
will behave in the fashion that you expect.
This is because python keeps references to objects. When you say bb = aa,
you are really saying, "Ta
> i'd like to know, too. my take so far is
>
> * don't make any copies if you can avoid doing so,
> * make shallow copies if need be,
> * make deep copies only if you can't think of any
> other way to accomplish what you're up to.
Yep. That's pretty much it, for space reasons, mostly. Imagine a li
time.sleep is not exactly accurate, so I would suggest that you use this
method, short 5 minutes or so and then do a sleep(10) or so in a loop to get
closer to the time.
>>import time
>>b = '20:00:00'
>>
>>(bhour, bmin, bsec) = b.split(':')
>>bsec = int(bsec) + int(bmin)*60 + int(bhour)*360
>>
> Considering the fact that choices[x] == x, shouldn't it be :
> del choices[proxyq]
choices = [9,2,1,3,6,4,7,8,5,0]
for idx, x in enumerate(choices):
print idx == x
False
False
False
True
False
False
False
False
False
False
Not always.
___
Tutor
> choice() returns a random element from the list of choices, not its index.
> One could call pop() instead of del, but del is probably a little faster,
> and
> doesn't return a value that we wouldn't use anyway. pop() wouldn't give
> us a
> random element, unless passed a random argument, such
>> class SubClass(BaseClass):
>> def __init__(self, t, *args, **kw):
>> super(SubClass, self).__init__(*args, **kw)
>> # do something with t
> Is there a proper way to handle the case when SubClass() is called using
> positional arguments, and you do not desire "t" to be at th
This is Windows I presume?
Try:
cd\python25
python C:\Elliot\filename.py
But for windows you shouldn't have to. You can just double-click the file.
On the other hand, if you mean 'import' as it means in the context of the
actual python language, then you would put the line "import filename" at
Woah. Either you're leaving out essential info, or python got a lot more
complicated.
Firstly, super returns all base classes. How? Does it return a tuple of
them, or a container object, or is this something horribly worse such as
syntactic sugar?
It doesn't make sense for it to return a tuple
of super... was it there in
previous versions of python?
- Original Message -
From: "Andreas Kostyrka" <[EMAIL PROTECTED]>
To: "tiger12506" <[EMAIL PROTECTED]>
Cc:
Sent: Friday, March 21, 2008 4:25 AM
Subject: Re: [Tutor] Calling super classs __init__?
my problem is, INSIDE the funcion...the variable erro is correct, but
when i return it to the test...and the test prints itcomes out 0.0.
Its disturbing...i didnt found a way of solving this.
err is defined in the function so it thinks it's a local variable. You can
set it to change only th
It's actually considered a mistake.
The original rationale is spelled out in PEP 234 - see the Resolved Issues
section:
http://www.python.org/dev/peps/pep-0234/
It is being renamed to __next__() in Python 3.0 and there will be a
builtin next() method that calls it. Instead of iterator.next()
ing global erro and
then using modulename.erro when he uses the actual value.
- Original Message -
From: "Kent Johnson" <[EMAIL PROTECTED]>
Cc:
Sent: Monday, April 21, 2008 9:33 PM
Subject: Re: [Tutor] Little problem with math module
tiger12506 wrote:
my probl
How is the window being closed? By someone forcing it to close? Or
terminating the process? If someone is just closing the window you can setup
an atexit handler that will close the socket before it finishes. However, if
the process is being terminated, then you will have to use one of the other
101 - 182 of 182 matches
Mail list logo