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
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
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()
and
then using modulename.erro when he uses the actual value.
- Original Message -
From: Kent Johnson [EMAIL PROTECTED]
Cc: tutor@python.org
Sent: Monday, April 21, 2008 9:33 PM
Subject: Re: [Tutor] Little problem with math module
tiger12506 wrote:
my problem is, INSIDE the funcion
... was it there in
previous versions of python?
- Original Message -
From: Andreas Kostyrka [EMAIL PROTECTED]
To: tiger12506 [EMAIL PROTECTED]
Cc: tutor@python.org
Sent: Friday, March 21, 2008 4:25 AM
Subject: Re: [Tutor] Calling super classs __init__?
class A(object):
v=lambda self
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
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 as
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
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
while True:
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 list
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,
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.
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
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 how do
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 see
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.argv[1][:-3]+'csv'
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 type 'str'
x can never be 11, but can possibly be '11'. (Notice quotes indicating
string instead of
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
extent
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 increment the
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 exception
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 views is this:
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'] = 'YY'
list.append(x)
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 is
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
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
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
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 .jpg...
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 iterations
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-07
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
PYTHONPATH is
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 this
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 in
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, how
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
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 if it is,
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.
Python
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 :
if
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 with
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
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:
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 while
snip
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 =
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
the
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 -
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 I
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.
[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
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. The
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'
basename =
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
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 file from
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 printall(*li):
for x in li
to the
user of the object.
For an implemented simple example just say the word.
HTH,
Tiger12506
PS. Anyone who's interested. A significant study of C has brought me to
these conclusions.
immutable - implemented with static buffer
mutable - implemented with linked list
Anyone know a little more detail
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
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
original
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 interaction (e.g. the cmd module
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
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 the
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
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. What I
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
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 -
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
- Original Message -
From: dave selby [EMAIL PROTECTED]
To: Python Tutor tutor@python.org
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 the
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.
Try this.
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 test to 1 then
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 syntax.
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
Mmm, to nit-pick a little, dictionaries are iterables, not iterators. They
don't have a next() method.
I'm a little fuzzy on the details of that, I will have to look over some
reference material again.
[a for a in eventData if eventData[a] time.time()]
This is more efficient. The keys
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 indeed. There is also
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
your
My apologies for mistaking your gender. Because English does not have
adequate neutral gender indication, I tend to use the male as such, as they
do in Spanish, and perhaps many other languages. At any rate, that's how
it's written in the Bible.
I presumed that it was an issue with raw input
Despite what your english teacher might have tried to make you
believe, they were wrong about the lack of a neutral in english. Just
like ending sentences with prepositions has always been done and
always will be done, the use of they to refer to someone of
indeterminate gender has been well
johnf [EMAIL PROTECTED] wrote
if self._inFlush:
return
self._inFlush = True
AND
if not self._inFlush:
...
self._inFlush = True
else:
return
I can not see the difference but the second one acts differently in
my code.
The first has no else clause so the
I may sound like a know-it-all, but dictionaries *are* iterators.
[a for a in eventData if eventData[a] time.time()]
This is more efficient. The keys method creates a list in memory first and
then it iterates over it.
Unnecessary.
Che M [EMAIL PROTECTED] wrote
Although I was not familiar
Hey Tiger,
your system clock is set incorrectly and your e-mail was flagged as being
sent 12/12/2008, causing it to appear after an e-mail sent as a reply -
confusing.
Please remedy this situation ;P
-Luke
Whoops!! I have to mess with my clock occasionally to test the integrity of
date
The OP has not specified what his problems specifically are, but earlylight
publishing described his problem before, and he was not understanding why
the prompt was expecting immediate keyboard input when he typed in
raw_input(). So a noob cannot figure out why it is advantageous to have a
Write a python script that prints out what 2+2 is NOW!!!
And after you've done that, write one that does my chemistry homework,
IMMEDIATELY!
Bonk!
;-)
JS
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
From your description, it sounds like the number of ovals placed depends
only on when the B1-Motion even is sent to your Canvas object. If you want
these a little more even, you might take the drawing code out of the
function that's bound to the mouse event, so that whenever you process you a
##
s = '/home/test/'
s1 = s.lstrip('/ehmo')
s1
'test/'
##
Take a closer look at the documentation of lstrip, and you should see
that
what it takes in isn't treated as a prefix: rather, it'll be treated as a
set of characters.
But then
I do not currently have wx installed, but I can see the errors...
I think some information will help you more than answers in this instance.
When you 'import clases_calling', what you are doing is creating a new
namespace. Inside that namespace is the class 'funct'. In your code, you
call the
s=set()
[s.add(tuple(x)) for x in myEntries]
myEntries = [list(x) for x in list(s)]
This could be written more concisely as...
s = set(tuple(x) for x in myEntries)
myEntries = [list(x) for x in list(s)]
Generator expressions are really cool.
Not what the OP asked for exactly. He wanted to
Sounds like an excuse for a global (aggh!) variable.
Or more properly, wrap all of the relevant functions in a class and use a
class variable for your puzzle
- Original Message -
From: Devon MacIntyre [EMAIL PROTECTED]
To: tutor@python.org
Sent: Wednesday, November 28, 2007 4:00 PM
Okay. Class is not a module. It is a keyword that defines a new type.
Similar to an integer, or a string. But in the case of a class, you define
what happens when you add, subtract, open, close, etc. by defining methods
of a class. A classic example is a car.
class Car:
running = 0
OK, the analogy is cute, but I really don't know what it means in
Python. Can you give an example? What are the parts of an old-style
class that have to be 'ordered' separately? How do you 'order' them
concisely with a new-style class?
Thanks,
Kent
He is setting up the analogy so that
If you run this code
#
f = open('test1.mlc')
for line in f:
print f.split()
#
You will see that about halfway through the file there is an empty list. I
assume that there was nothing on that line, in which case, there is no [0]
value.
In which case, you need to put in a try: except
Sorry about that. I want something like:
class foo:
def __init__(self):
self.attr1 = None
def get_attr1(self):
if not self.attr1:
attr1 = get value from DB, very expensive query
self.attr1 = attr1
return self.attr1
such
Hi everyone -
I'm beginning to learn how to program in python. I need to process
several text files simultaneously. The program needs to open several files
(like a corpus) and output the total number of words. I can do that with
just one file but not the whole directory. I tried glob but
The point is that even though eval(raw_input()) is not a security threat,
Alan's suggestion of myscript.py some.txt might be. And even though the
script written will not be a security issue, the *coding practice* that it
teaches will lead to times when he does encounter that tiny set of
scenarios
foo = raw_input(...)
x = eval(foo)
Is an exception, in almost[*] every scenario I can think of. (and is the
context eval was being used as far as I can see without reading the whole
thread)
[*] One scenario that seems unlikely but possible is a scenario where a
machine has been
On Monday 13 August 2007 22:39, Tiger12506 wrote:
foo = raw_input(...)
x = eval(foo)
...
Let your program run on your machine and I'll walk by, type in this
string,
and hit enter. We'll see how much of an exception it is when you can't
boot
your XP machine anymore.
;-)
Who cares
It seems this is a delightful exchange of rude threats and insults. ;-)
My question is: If you love C syntax so much, why don't you program in C and
leave us python people alone?
And also: It is not the responsibility of the docs to ease the way for C
programmers. That is what a specific
Dick Moores wrote:
(I posted this to the python-list 24 hours ago, and didn't get a
single response. How about you guys?)
You mean this list? Cause if you mean this list, then you didn't post
it correctly.
I don't believe he did. There are seperate python-lists, comp.lang.python,
one
Traceback (most recent call last):
File domainspotter.py, line 150, in module
runMainParser()
File domainspotter.py, line 147, in runMainParser
td.run()
File domainspotter.py, line 71, in run
checkdomains.lookup()
File domainspotter.py, line 108, in lookup
from rwhois
1 - 100 of 172 matches
Mail list logo