Re: [Tutor] python interpreter vs bat file

2009-07-18 Thread Alan Gauld
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/ __

Re: [Tutor] python interpreter vs bat file

2009-07-19 Thread Alan Gauld
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

Re: [Tutor] hitting a wall (not a collision detection question :P)

2009-07-19 Thread 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, --

Re: [Tutor] UnicodeEncodeError

2009-07-19 Thread Alan Gauld
"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

Re: [Tutor] Using insert method on a list matrix

2009-07-20 Thread Alan Gauld
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

Re: [Tutor] Pygame

2009-07-20 Thread Alan Gauld
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

Re: [Tutor] advice on creating and working with a complex data structure

2009-07-20 Thread Alan Gauld
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

Re: [Tutor] advice on creating and working with a complex datastructure

2009-07-20 Thread Alan Gauld
"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

Re: [Tutor] Question from a newbie

2009-07-21 Thread Alan Gauld
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

Re: [Tutor] code structure terminology and advice

2009-07-22 Thread Alan Gauld
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/ ___

Re: [Tutor] demo/turtle

2009-07-22 Thread Alan Gauld
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

Re: [Tutor] xlwt & xlrd: can I refactor this code better?

2009-07-22 Thread Alan Gauld
, 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

Re: [Tutor] how to fill zero value and join two column

2009-07-22 Thread Alan Gauld
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)...

Re: [Tutor] xlwt & xlrd: can I refactor this code better?

2009-07-23 Thread ALAN GAULD
> 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

Re: [Tutor] Mapping of co-ordinates... pygame

2009-07-23 Thread Alan Gauld
"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

Re: [Tutor] dictionaries help

2009-07-23 Thread Alan Gauld
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

Re: [Tutor] dictionaries help

2009-07-23 Thread Alan Gauld
"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

Re: [Tutor] reading data

2009-07-23 Thread Alan Gauld
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

Re: [Tutor] how to get blank value

2009-07-24 Thread Alan Gauld
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

Re: [Tutor] how to get blank value

2009-07-24 Thread ALAN GAULD
;> 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

Re: [Tutor] Reading text until a certain point

2009-07-24 Thread Alan Gauld
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

Re: [Tutor] Reading text until a certain point

2009-07-24 Thread Alan Gauld
"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

Re: [Tutor] Reading and Manipulating XML Data

2009-07-25 Thread Alan Gauld
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

Re: [Tutor] Need to be pointed in the right direction for fileorganisation.

2009-07-25 Thread Alan Gauld
(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

Re: [Tutor] how to get blank value

2009-07-25 Thread Alan Gauld
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;

Re: [Tutor] Need to be pointed in the right direction for file organisation.

2009-07-25 Thread Alan Gauld
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

Re: [Tutor] reading into a text file

2009-07-25 Thread Alan Gauld
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

Re: [Tutor] First code snipet

2009-07-26 Thread Alan Gauld
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/ _

Re: [Tutor] First code snipet

2009-07-26 Thread Alan Gauld
"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:

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Alan Gauld
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

Re: [Tutor] renaming files within a directory

2009-07-27 Thread Alan Gauld
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/ ___

Re: [Tutor] How to use Python 2.6 with IDLE?

2009-07-27 Thread Alan Gauld
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

Re: [Tutor] How to use Python 2.6 with IDLE?

2009-07-27 Thread ALAN GAULD
> > 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

Re: [Tutor] Eng to Leet Speek

2009-07-27 Thread Alan Gauld
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

Re: [Tutor] How to use Python 2.6 with IDLE?

2009-07-27 Thread Alan Gauld
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

Re: [Tutor] How to use Python 2.6 with IDLE?

2009-07-27 Thread ALAN GAULD
> 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

Re: [Tutor] Help...

2009-07-28 Thread Alan Gauld
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

Re: [Tutor] self.name vs. passing a name

2009-07-28 Thread Alan Gauld
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

Re: [Tutor] how to get blank value

2009-07-28 Thread Alan Gauld
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

Re: [Tutor] Two problems related to dispathing.

2009-07-28 Thread Alan Gauld
"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

Re: [Tutor] how to know if process is running?

2009-07-28 Thread Alan Gauld
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

Re: [Tutor] Problem with multiple input

2009-07-28 Thread Alan Gauld
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

Re: [Tutor] concerning help() function

2009-07-29 Thread Alan Gauld
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

Re: [Tutor] concerning help() function

2009-07-29 Thread Alan Gauld
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 __

Re: [Tutor] (no subject)

2009-07-29 Thread Alan Gauld
"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

Re: [Tutor] mnemonics to better learn Python

2009-07-31 Thread Alan Gauld
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

Re: [Tutor] mnemonics to better learn Python

2009-07-31 Thread Alan Gauld
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

Re: [Tutor] How to pass arguments to struct.pack()?

2009-08-03 Thread Alan Gauld
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

Re: [Tutor] Buffering when reading files !

2009-08-04 Thread Alan Gauld
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/ _

Re: [Tutor] Program to Simulate Keystrokes

2009-08-04 Thread Alan Gauld
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

Re: [Tutor] Scope of exceptions

2009-08-05 Thread Alan Gauld
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/ _

Re: [Tutor] Configuaration files and paths?

2009-08-05 Thread Alan Gauld
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

Re: [Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Alan Gauld
"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

Re: [Tutor] noob question (Windows, Python 3.1)

2009-08-06 Thread Alan Gauld
"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

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Alan Gauld
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

Re: [Tutor] clear screen inside python interpreter

2009-08-06 Thread Alan Gauld
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) --

Re: [Tutor] need help

2009-08-06 Thread Alan Gauld
; 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

Re: [Tutor] this module

2009-08-08 Thread Alan Gauld
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

Re: [Tutor] How to Split a String

2009-08-08 Thread Alan Gauld
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

Re: [Tutor] droplet like behaviour in Python

2009-08-08 Thread Alan Gauld
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.

Re: [Tutor] this module

2009-08-09 Thread Alan Gauld
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

Re: [Tutor] hi everyone!

2009-08-09 Thread Alan Gauld
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/ ___

Re: [Tutor] droplet like behaviour in Python

2009-08-10 Thread Alan Gauld
"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.

[Tutor] Tutorial update

2009-08-10 Thread Alan Gauld
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

Re: [Tutor] Tutorial update

2009-08-10 Thread Alan Gauld
"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

Re: [Tutor] Fixing "nearly ASCII" data file?

2009-08-10 Thread Alan Gauld
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

Re: [Tutor] run python script on another computer's terminal (LAN)

2009-08-11 Thread Alan Gauld
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

Re: [Tutor] To write data in two different fonts?

2009-08-12 Thread Alan Gauld
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

Re: [Tutor] creating an exe

2009-08-12 Thread Alan Gauld
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

Re: [Tutor] best approach to db-api imports and cursor calls

2009-08-13 Thread Alan Gauld
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/ _

Re: [Tutor] Dynamic Function Calls

2009-08-13 Thread Alan Gauld
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

Re: [Tutor] Web framework: looking for python-tutor's angle.

2009-08-13 Thread Alan Gauld
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

Re: [Tutor] rationale for nested classes?

2009-08-14 Thread Alan Gauld
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

Re: [Tutor] python's database

2009-08-15 Thread Alan Gauld
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

Re: [Tutor] Iterating through objects

2009-08-16 Thread Alan Gauld
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

Re: [Tutor] python and java report writers

2009-08-17 Thread Alan Gauld
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

Re: [Tutor] rationale for nested classes?

2009-08-17 Thread Alan Gauld
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

Re: [Tutor] How to format JSON output within script

2009-08-17 Thread Alan Gauld
"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. ___

Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Alan Gauld
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

Re: [Tutor] Question if my reasoning is right

2009-08-19 Thread Alan Gauld
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

Re: [Tutor] handling a textfile

2009-08-19 Thread Alan Gauld
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

Re: [Tutor] Help on input error

2009-08-21 Thread Alan Gauld
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

Re: [Tutor] how do we represent left arrow key in python programming.

2009-08-21 Thread Alan Gauld
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

Re: [Tutor] get name of calling class at runtime

2009-08-21 Thread Alan Gauld
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/

Re: [Tutor] get name of calling class at runtime

2009-08-21 Thread Alan Gauld
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/ __

Re: [Tutor] get name of calling class at runtime

2009-08-22 Thread Alan Gauld
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, --

Re: [Tutor] simple plots

2009-08-22 Thread Alan Gauld
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

Re: [Tutor] get name of calling class at runtime

2009-08-22 Thread Alan Gauld
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

Re: [Tutor] Algorithm

2009-08-23 Thread Alan Gauld
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

Re: [Tutor] Algorithm

2009-08-24 Thread Alan Gauld
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

Re: [Tutor] Ptyhon GUI doubt

2009-08-26 Thread Alan Gauld
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

Re: [Tutor] design advise

2009-08-26 Thread Alan Gauld
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

Re: [Tutor] Declaration order of classes... why it is important?

2009-08-26 Thread Alan Gauld
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

Re: [Tutor] Callbacks in Python

2009-08-27 Thread Alan Gauld
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/ ___

Re: [Tutor] design advise

2009-08-27 Thread Alan Gauld
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

Re: [Tutor] Declaration order of classes... why it is important?

2009-08-28 Thread Alan Gauld
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

Re: [Tutor] What does it mean to create separate applications?

2009-08-28 Thread Alan Gauld
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

Re: [Tutor] flyweight pattern using Mixin vs. Inheritance

2009-08-28 Thread Alan Gauld
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.

Re: [Tutor] Running two applications at once

2009-08-28 Thread Alan Gauld
"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

Re: [Tutor] Making sense of "'python' is not recognized as an internalor external command...

2009-08-28 Thread Alan Gauld
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!

<    8   9   10   11   12   13   14   15   16   17   >