Which folders are you starting from in each case?
This has happened before and it seems odd behavior.
So how did you fix it before?
I've never seen or heard of this before.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
__
u could try usng the start command instead, as in:
start foo.py
You might want to explore the /I, /B and /WAIT options
start gives you a lot more control over the execution environment.
Notice you don;t need the 'python' because start uses the file
association.
HTH,
--
Alan Gauld
mewhat academic.
this is about as specific as I can be.
Go back to those tutorials and find the bits you aren't sure about
and just ask - what does this mean? How should I use this? And why?
Is this a sensible way to program this? etc etc... We will try to help.
HTH,
--
"Mark Tolonen" wrote
... I see you are using Python 3.1. ...
You can also use a shell that supports the full Unicode character set
such as Idle or PythonWin instead of the console.
As a matter of interest - and somewhat off topic - does anyone
know if there is a Python 3 (3.0 or 3.1) versi
the insert syntax right this time. M should now
look like
M=[[1,2,3], 'pod', [3,2,1], [4,3,2]]
M.insert(1,'pod')
M
[[1, 2, 3], 'pod', 'pod', [3, 2, 1], [4, 3, 2]]
You got it right here too but you are inserting it into M not
into the first element of M
t;hard core" - like C++ - you will
find the lessons you learned in Python still apply. Once you know one
programming language learning a new one is very much easier.
Finally, stick to Python v2 just now, Python v3 is not best suited to
beginners yet.
--
Alan Gauld
Author of the Lear
bject to handle
fetching the stuff from its next level down would be simpler
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
"Serdar Tumgoren" wrote
Aha, okay, the multiple classes approach makes sense. But would these
be nested classes,
No although they would probably have attributes containing
the related lists. Thus Race might have a list of Candidates.
And Candidate would have a list of Committees etc.
perh
p right on the home page...
And of course it is also a great scripting language to replace
DOS batch files, Unix shell scripts and awk/sed/perl/Tcl etc etc
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tuto
ng about business process execution
languages gives you some ideas about how to structure and
represent complex processes. BEPL would be a good
starting point, again try Wikipedia.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
odule should be installed as standard on 2.6.
So the example code should just work.
Which OS are you on? Some Linux versions of Python
don't have Tkinter loaded and that will probably prevent
turtle from running...
What happens when you try it? Do you get an error message?
--
Alan Gauld
Au
, that's a lot of work for the client just
to save you doing
class XLSFileError(Exception): pass
and
raise XLSFileError()
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
an overly elaborate solution. You could
simplify the last for loop to just do
for m in merge([source(a),source(c)])
But of course that is a recursive function call to merge() and I
can't see any terminating condition so it should loop forever
(or until it reaches the recursion limit)...
> Btw, I see that you're the author of a Python book. I am using Python for my
> work as a researcher. Should, in your opinion, the learning strategy for
> somebody like me vis-a-vis somebody who is becoming a professional programmer
> be
> very much different?
Not in the early days. The ar
"Wayne" wrote
def draw_pixel(x, y):
w = screen.get_width()
h = screen.get_height()
screen.draw_pixel(w/2+x, h/2+y)
I think that should be h/2-y for the coordinates given?
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.pytho
aaa'
from the above i would like to compare my_code and return the
dictionary which has code == my_code
Vince has shown you one way, this is another way:
def findDict(value, dictList):
for dct in dictList:
if dct.get('code', '') == my_code
retu
"Alan Gauld" wrote
Oops!
Should be:
def findDict(value, dictList):
for dct in dictList:
if dct.get('code', '') == my_code
if dct.get('code', '') == value
return dct
HTH,
--
Alan Gauld
Author of the
umn]=data[column]
However I'm still not totally clear what you are achieving with this?
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
expr = re.compile("C = None")
This will search for the literal string 'C = None' which does not exist in
your sdata.
You need to search for 'C = 'at the end of the line (assuming it is always
there.
Otherwise you need to search for 'C = ' followed by a non
;> import re
> >> expr = re.compile("C = None")
> >
> > This will search for the literal string 'C = None' which does not exist in
> > your sdata.
> > You need to search for 'C = 'at the end of the
a
dict) with that group. I would then probably split it into various
elements.
Just one alternative...
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
"Alan Gauld" wrote
class Item(object):
def __init__(self, aFile):
data = aFile.readline().strip().split(:)
setattr(self, data[0], data[1])
The last two lines should of course be repeated 3 times...
Either in a loop or - for just 3 items - maybe hard coded...
it
reading Text Processing in Python which is a book
but also available online at:
http://gnosis.cx/TPiP/
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
(Zope, Django etc being
good examples of exceptions! :-)
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
wrote
With these commands:-
import re
f = open('chem.txt')
for line in f:
if re.search('C = ',line):
print line
I am getting those lines for which C value is there but how to get those
one for which it doesn't have any value, i did google search but still i
am not getting.
Don;
e structure
should be a hint of how dependency works,
No, just that you should try to keep low level functuions etc in
separate files and have the higher level, more abstract modules
import them. Rather than mixing low level, implementation
dependant coded with more abstract - and therefore
ach "line" starts with a paragraph tag followed immediately
by a bold tag, is that really what you want? If so it looks fine.
You could modify your program so that it takes the filename at the
command line, so you can process more than one file:
python myscript foo.html
or
pytho
s OK to me.
You might be able to leverage the stdlib more effectively, for
example there is a shuffle type menthod for randomising a
single list. And zip() to merge two lists...
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_
"Dave Angel" wrote
len() is very fast, so there's no need for a separate variable to keep
track of the lengths of inpile1 and inpile2. So eliminate all refs to
pile1c and pile2. In the while, just use
while len(inpile1) and len(inpile2):
Or even simpler:
while inpile1 and inpile2:
using the
os.path.splitext() function.
Also, How do I remove 'Flag_of', 'Flag_of_the_'
You could try replacing with a null string. Do the second one first
followed by the first if necessary, using the string.replace() method.
HTH,
--
Alan Gauld
Author of the Learn to Pr
cess the dictionary.
$ python rename_svg.py
Uganda flag-ug.svg
Where does the Uganda come from? Loooks like the
real code has an extra print statement somewhere?
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
tcut which specifies
the full path to the interpreter and to the pyw file. I also set the
working foldeer to wherever is most appropriate - usually my
project folder. That's fairly bulletproof in my experience!
HTH,
--
Alan Gauld
Author of the Learn to Program web sit
> > What I do for these things is create a shortcut which specifies the full
> > path to the interpreter and to the pyw file. I also set the working foldeer
> > to wherever is most appropriate - usually my project folder. That's fairly
> > bulletproof in my experience!
>
> Alan, here's what have
ot;c")
astring = astring.replace("|)","d")
You might want to investigate the maketrans and translate
functions in the string module.
The seem to be quite similar in intent to what you are trying
to do?
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://w
r to run programs that may be
defined in ulipad's config details somewhere - either an ini file or
in the registry. In which case find it and edit it manually.
Or it could be by ulipad reading it from the environment - in which
case there won't be much you can do!
HTH,
--
Alan
> I get a console for a fraction of a second. Can't read anything it says.
>
> > Or just try typing the command into a console session till
> > you get one that works!
>
So what happens when you run the same command from a console?
That should leave the errors visible.
> I'm not sure how to
es that were in the
calc_total function
Would you like to end your order? (Enter yes or no)yes
*Traceback (most recent call last):
File "...", line 74, in
main()
File "...", line 16, in main
sodaPrice = input_soda()
File "...", line 51, in in
ise the second merthod is just a variation in storing the
result in a global variable wjhich is generally considered a bad
design style.
In general keep data as close to its point of use as possible.
HTH,
--
Alan Gauld
Author of the Learn to Program web sit
does not match the end of line.
The regex character for end of line is $ thus you should find something
like
RE = re.compile('C =$')
You might need to allow for whitespace between the = and $...
If the blanks are not at the end of the line things get slightly more
compli
"Mac Ryan" wrote
above function. In fact, as I have the need to access the object both
individually and with the dispatcher, I am doing something like this
every time I instantiate a new object:
mycontent = ContentA()
contents.append(mycontent)
...but although I "feel" this is silly, I
fork() or exec() to create the
real new process...
Finally you can write a signal file into /tmp and then look for that
file on startup. Don't forget to delete it when you exit though!
Lots of options depending on how hard core you need to be!
HTH,
--
Alan Gauld
Author of the Learn to P
sing spaces and commas - and I suggest adding
semi colons and tabs too?
number1, number2 = (input("Please enter two numbers: ").split("
,;\t"))
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
ror,
error mainly.
What you are seeing is the help for the string 'operator' - which
is the same as the help for any other string - the builtin string
methods. Comparte it with
help('')
HTH,
--
Alan Gauld
Author of the Learn to
help('operator')
I figured this by trial and error, and I am keen to find out when the
Oops, always try before posting! And don;t assume...
I juast vdid and you are right, it does give help on an unimported module!
Sorry, how embarrassing! :-)
Alan G
__
"Chris Castillo" wrote
# Module demonstrates use of lists and set theory principles
could this be done in a more elegant fashion?
Yes use the Python set type.
Alan G
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinf
uage has an equivalent for both of those
concepts?
In hardware engineering its more complex because you have
nand and nor gates to deal with too, but they don't apply in
software - at least not directly.
--
Alan Gauld
Author of the Lear
the first failure
for and or the first success for or.
It might be cute to have an aide d'memoire for that.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/m
st)
fmt = "i%di" % ln
return struct.pack(fmt, ln, *aList)
That makes it easier to decode if/when you want to read it back.
You will find an example in my tutorial under Handling files.
HTH,
--
Alan Gauld
Author of the Learn to Program we
S will lock the file even for
reading)
Personally I've never found buffering to be of any real impact for
reading files. Writing files is another matter of course.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_
this simple but if I have to use
two different programs I will.
stdin/out should work on both.
If its a GUI program then things get much more complicated!
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tuto
th it, so it raises it to the
next level where your handler should catch it.
So what does your real handler look like?
And what does the exception that is raised look like?
HTH
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_
tabase. If the environment var is not set then
look in ./config
2) How should I point to those other folders in the ini file?
Once you locate config the others are simply ../xxx relative
to config.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.al
"Joshua Harper" wrote
Ok, so I am trying to learn python, and I am reading many tutorial type
If you are just learning Python downgrade from 3.1 to v2.6.
Most tutorials are not up to 3.1 yet and there are many differences.
v3.1 was a big change to the language.
eg. The following code is for
"Che M" wrote
C:\Windows> python some\path\to\myscript.py
That way you will still see the error message after the
program finishes.
Or what about using IDLE?
Good point, although IDLE can bring its own problems.
But for this case IDLE would be a good choice.
--
Alan
p., I then pass that data
around in my functions.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
al control is very system dependant.
Fred Lundh did crate a platform independant console module that
allowed cursor control and clearing of screens etc. Google should
find it for you.
But in your case os.system() or subprocess.call() are probably your
best bet. or just print('\n' *100)
--
;
So where do you think you define xpos and ypos?
You cannot use them until you define them by assigning a value.
xpos -= movement_x
is just shorthand for
xpos = xpos - movement_x
You cannot use xpos on the right before you give it an initial value.
HTH,
--
Alan Gauld
Author of the
o the encrypted string.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
nd basename functions
useful for mamnipulating paths. Especially if you need to do it on
multiple different computers/OS. These are in the os/os.path
module family.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
e path and
shebang etc set up properly that it just happened. Have you tried
a simpe script that just prints argv say?
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.
To define foo you need to execute those two lines of code.
The result is that you create a function object.
So when you import a moduile it runs all of the code in there, and
most of the code usually consists of function and variable definitions.
But it can be anything at all.
HTH,
--
Alan Gaul
laining what is
bugging you and any code plus error messages. (It
also helps to mention the Python version, the OS and
the tutorial you are using)
Either way have fun.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
"pedro" wrote
Well I made a script called droplet.py which looks like this:
#!/usr/bin/env python
# encoding: utf-8
import sys
theFilePath = sys.argv[1]
print theFilePath
But when I try to drop something on it nothing happens. Sorry I guess
there is something fundamental that I am missing.
Just a note to say that the v3.1 version of my tutor has reached another
milestone.
I just uploaded the last topic in the Basics section which means the
tutorial is
now sufficiently complete that it could be used by a beginner to learn V3
Python.
It hasn't had enough traffic to call it good qu
"Alan Gauld" wrote
I just uploaded the last topic in the Basics section which means the
tutorial is now sufficiently complete that it could be used by a
beginner to learn V3 Python.
And the v3 url is, of course:
--
Alan G
Author of the Learn to Program web site
http://www.al
nts?
You should be able to process it using the string translation methods with
a one to one conversion.
try help(''.translate)
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor mail
general sense you can use ssh (or rsh?) to do that.
You might also be able to avoid using subprocess or os.system
by mounting the remote filesystem? That would let you you
os.listdir() on the remote machine?
HTH
--
Alan Gauld
Author of the Lear
en it in a simple text editor like notepad or nano and see what
it looks like.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
ve to install yet another version of python, and so on,
which very rapidly becomes more wasteful than the first method.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
n each change transaction.
But most folks find multiple cursors easier to manage in the same
way that they find multiple variables easier than reusing a minimal
number.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_
fined func0!
try adding
def func0(): print 'func0'
def func1(): print 'func1'
def func2(): print 'func2'
above your function.
Then it might work if you call you function like this:
myFunc([func2,func0,func1])
HTH,
--
Alan Gaul
EA Weblogic etc..
But for SMEs Django (et al) is ideal.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
child
relationships where appropriate?
Yes, but nesting really has nothing to do with inheritance.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
were thinking of?
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
as a list
print lines[2],lines[5], lines [-1] # 3rd, 6th and last as lines
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
er object.
You just have to run the data producer under CPython and the report
writer under Jython. (Or compile it to run under Java)
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - T
g. They are very different concepts. Nesting tends
to make subclassing more difficult (albeit in Python only trivially so)
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
"Vincent Gulinao" wrote
I see you could pipe your output to 'python -mjson.tool', but how do I
achieve the same within my script?
We don't charge you by the word.
A wee bit more explanation and background would be useful please?
What are you trying to do exactly?
Alan G.
___
ite.py is probably better
than setting a System wide PYTHONPATH though) But again
site.py applies to every application you should not start modifying
it with application specific startup code - yuck! It could soon turn
into spaghetti and seriously slow down startup of everything.
HTH,
--
Alan Gau
wing:
cb = [[[0,None] for x in range(n+1)] for y in range(m+1)]
Yes, that's what list comprehensions are for, to create lists.
Is this an acceptable practice?
Absolutely. It is one of the most common uses for comprehensions.
--
Alan Gauld
Author of the Learn to Program web site
htt
and such, but I'm no itertools expert - its on my list of things to
learn... :-)
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
keep a separate Projects area outside my python
installation and reference it via PYTHONPATH., That means if I delete
a Python installation, including site-packages-oops! - or install a
second one I can still access my modules or share thjem across both
without copying.
Just a thought,
--
Alan
r"
while True:
ky = msvcrt.getch()
length = len(ky)
if length != 0:
# send events to event handling functions
if ky == " ": # check for quit event
doQuitEvent(ky)
else:
doKeyEvent(ky)
HTH,
--
Alan Gauld
Aut
kind of problem?
There are ways of doing what you want, but the "standard" way is
to keep the code for class A in class A. Thats why its called
Object Oriented programming.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
ld pass the instance of C to DataSources.
(and you can use isInstance() to check its type).
But unless you have a really good reason its still better
to get the class to do its own SQL. IMHO.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
__
le that accessed the real
instance attributes(like tablename). That could then be inherited by
all Storable objects. That way you get the common code and avoid
the case statement based on type.
PS. I know Kent knows about mixins, the explanation was for
anyone else who is intrested :-)
HTH,
--
be some modules that can
help but we can't tell which yet.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
te sql for callerA
def getBdata(self):
#execute sql for callerB
You might as well just put them as functions in a module, but
you still have the double file maintenance issue.
--
Alan Gauld
Author of the Learn to Program web site
http://www.al
r things like double letters,
eg see. - is ese the same as ese? (the e's are swapped, honest!...)
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
nt lettercount.iteritems()
Although I'm not sure that would actually print what you expect!
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
hole bunch of extras
including
all of the python documentation in Windows help format.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
wrote
In my application I need to choose how to store data for each user, for
example:
/news
/articles
/games
My difficulty now comes in how to store this data in that I will need to
create views
Which is the more efficient option for storing this data, is it better to
have
all in one pl
brick, if you put together bricks you get a wall, if you put together
walls you get..."]
You can put the top level function in a separate module and import
the lower level ones, similarly you can put the class definitions in
separate modules. But IMHO its better to just get used to Pythons way
of wo
ntrol
depending on event type. The typical implementation will see the
event framework storing the callbacks in some kind of dictionary
keyed by event type.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
is to build the relationships in the
database but keep the resources in the filesystem. You can then
query the database for which resources to display then access
the resources directly from disk using their filenames etc
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http
r your
own good! :-)
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
our boss wants a separate exercutable python script for
each main form. By using modules you should be able to reuse a lot
of your database code between the different applications.
You will find more on this topic in the "What is Programming" topic
in my tutorial.
HTH,
--
Alan
return ID
def __init__(self, *args, **kwargs):
if ID in self.instances:
return
else:
# init as usual.
def __del__(self):
del( self.instances[self.ID] )
The __del__ can probably be implemented in the top level class
and inherited.
"Dirk Wangsadirdja" wrote
Is it possible if I run two applications at once?
Yes, you just run two instances of the python interpreter.
They will happuily run independantly of one another or communicate
with each other as you wish. Its exactly the same as with Java or
Visual Basic or any ot
t every time.
This is done via MyComputer->Properties->Advanced->Environment Variables
Select Path and click Edit
Be very careful not to accidentally delete the existing path!
add your Python folder to the end of the existing path separating
it with a semi-colon.
That should work!
1201 - 1300 of 9948 matches
Mail list logo