Re: [Tutor] Calling super classs __init__?
> > What's the most "pythonic" way to make this work? > > class BaseClass(object): > def __init__(self, x, y, z, foo='foo'): # whatever > # etc > > class SubClass(BaseClass): > def __init__(self, t, *args, **kw): > BaseClass.__init__(self, *args, **kw) > # do something with t > > This does mean that the special sub class argument has to come before > the base class arguments when you create instances. > > Whether you call BaseCla Thank you... Excellent idea. I haven't tried it yet, but I suppose **kwarg.pop()'ing and *args manipulation could help ease subclass instantiation call signature limitations. (?) Thanks, :) Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling super classs __init__?
> > class MySubClass(MySuperClass): > > > > def __init__(self, just_a_sub_option): # what about other args? **args? > > I think I would go ahead and list the superclass parameters and put the > new one at the end: > def __init__(self, opt_1, opt_2, opt_3, opt_n, just_a_sub_option): > > > MySuperClass.__init__()# Should this be first? > What args to use? **args? > > MySuperClass.__init__(self, opt_1, opt_2, opt_3, opt_n) > > John's method will also work but I prefer to add the new parameter at > the end of the argument list. (Hmm.. I should have pointed out that I generally use keyword args. ) Right. So, I can certainly call the MySuperClass.__init__() with a long list of kwargs, but that gets annoying quickly when the superclass is also under active development and it's call signature frequently changes. Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling super classs __init__?
Nowadays the best practice for invoking a method from all superclasses (yes, multiple inheritance) is this: class SubClass(BaseClass): def __init__(self, t, *args, **kw): super(SubClass, self).__init__(*args, **kw) # do something with t That way you let Python decide which superclasses your SubClass has, instead of hard-coding it in several places. Cheers, Luciano On Tue, Mar 18, 2008 at 9:37 PM, John Fouhy <[EMAIL PROTECTED]> wrote: > On 19/03/2008, Allen Fowler <[EMAIL PROTECTED]> wrote: > > I have a super class that accepts many arguments to it's constructor, and > a subclass that should define one additional argument. > > > > What's the most "pythonic" way to make this work? > > class BaseClass(object): > def __init__(self, x, y, z, foo='foo'): # whatever > # etc > > class SubClass(BaseClass): > def __init__(self, t, *args, **kw): > BaseClass.__init__(self, *args, **kw) > # do something with t > > This does mean that the special sub class argument has to come before > the base class arguments when you create instances. > > Whether you call BaseClass.__init__ early or late in the subclass init > method could depend on what your classes are doing. Remember, in > Python, __init__ only initializes objects, it doesn't create them. > It's just another bit of code that you can call whenever you want. > > -- > John. > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] c++::return
I actually said "ending" to avoid problems with different terminology between different languages - but i guess a return is still a return in python. i did this search http://www.google.ca/search?hl=en&q=python+tutorial+return&btnG=Google+Search&meta= and it didn't return any particularly obvious answer. The funny thing is, i wrote that program last june and managed to not know/use a single return :) On Tue, Mar 18, 2008 at 6:11 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > "elis aeris" <[EMAIL PROTECTED]> wrote > > > how do I return a function? > > > Do you realise that this is an entirely different question > to the one you asked originally, namely: > > >> what do I do if i want the program/function to end? > >> > >> in c++ of > >>int main(){} > >>I do a return 0; > > > One is asking about *ending* the program(or function), the > other about returning. Those are two different concepts. > In particular returning implies that the program does not > end but goes on to use the returnedvalue in some way. > > Assuming that it is returning you are interested in then > all the tutorials that discuss Python functions (including > mine) will tell you how to return a value from a function. > > You use the return statement exactly like in C++. > > Where did you look if you couldn't find it? > > Even searching "return" on the Python web site gets me this as > the first link: > > 6.7 The return statement > When return passes control out of a try statement with a finally > clause, that finally clause is executed before really leaving the > function. ... > docs.python.org/ref/return.html - 7k - Cached - Similar pages > > > And visiting it it tells me: > > ---return_stmt ::= "return" [expression_list] > > > return may only occur syntactically nested in a function definition, > not within a nested class definition. > > If an expression list is present, it is evaluated, else None is > substituted. > > return leaves the current function call with the expression list (or > None) as return value. > - > > Now, its not that we mind answering questions, but if you claim > to have looked for an answer and then ask a somewhat vaguely > worded question we will assume you are looking for something > deeper. Its easier for all of us if you are as specific as possible > in your questions. > > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xrange
Oh i am good with range then, because it's not a real time program. On Tue, Mar 18, 2008 at 3:55 PM, Shrutarshi Basu <[EMAIL PROTECTED]> wrote: > I'm not entirely sure about this, but I think for range(), the entire > range of numbers is generated at one go, which could cause a > slow-down. But xrange() generates the list of numbers one at a time. > For a thousand, there shouldn't be much of a difference, but if you > need a million or so go with xrange() > Basu > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling super classs __init__?
Allen Fowler wrote: > What's the most "pythonic" way to make this work? > > class MySuperClass(object): > > def __init__(self, opt_1, opt_2, opt_3, opt_n): ># stuff done here > pass > > > class MySubClass(MySuperClass): > > def __init__(self, just_a_sub_option): # what about other args? **args? I think I would go ahead and list the superclass parameters and put the new one at the end: def __init__(self, opt_1, opt_2, opt_3, opt_n, just_a_sub_option): > MySuperClass.__init__()# Should this be first? > What args to use? **args? MySuperClass.__init__(self, opt_1, opt_2, opt_3, opt_n) John's method will also work but I prefer to add the new parameter at the end of the argument list. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] c++::return
"elis aeris" <[EMAIL PROTECTED]> wrote > how do I return a function? > Do you realise that this is an entirely different question to the one you asked originally, namely: >> what do I do if i want the program/function to end? >> >> in c++ of >>int main(){} >>I do a return 0; One is asking about *ending* the program(or function), the other about returning. Those are two different concepts. In particular returning implies that the program does not end but goes on to use the returnedvalue in some way. Assuming that it is returning you are interested in then all the tutorials that discuss Python functions (including mine) will tell you how to return a value from a function. You use the return statement exactly like in C++. Where did you look if you couldn't find it? Even searching "return" on the Python web site gets me this as the first link: 6.7 The return statement When return passes control out of a try statement with a finally clause, that finally clause is executed before really leaving the function. ... docs.python.org/ref/return.html - 7k - Cached - Similar pages And visiting it it tells me: ---return_stmt ::= "return" [expression_list] return may only occur syntactically nested in a function definition, not within a nested class definition. If an expression list is present, it is evaluated, else None is substituted. return leaves the current function call with the expression list (or None) as return value. - Now, its not that we mind answering questions, but if you claim to have looked for an answer and then ask a somewhat vaguely worded question we will assume you are looking for something deeper. Its easier for all of us if you are as specific as possible in your questions. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xrange
"Kent Johnson" <[EMAIL PROTECTED]> wrote >> Add a 3rd step-value argument to range. (You don't need the xrange >> on modern versions of Python BTW) > > Only if by 'modern' you mean Python 3; on Python 2.x there is a > difference between range() and xrange(). Though for a list of 20 > ints I > don't think it matters much. Ah! I thought the unification happened when generators were introduced I didn't realised it was put back to v3. Thanks for the pointer Kent. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] kwargs to object proporties?
On 19/03/2008, Allen Fowler <[EMAIL PROTECTED]> wrote: > Hello, > > What's the best way convert keyword arguments to object properties? You can mess around with self.__dict__.update(kwargs) or update(locals()). I'm not sure exactly what you want to do.. See this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286185 It has some suggestions and discussion that you might find helpful. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling super classs __init__?
On 19/03/2008, Allen Fowler <[EMAIL PROTECTED]> wrote: > I have a super class that accepts many arguments to it's constructor, and a > subclass that should define one additional argument. > > What's the most "pythonic" way to make this work? class BaseClass(object): def __init__(self, x, y, z, foo='foo'): # whatever # etc class SubClass(BaseClass): def __init__(self, t, *args, **kw): BaseClass.__init__(self, *args, **kw) # do something with t This does mean that the special sub class argument has to come before the base class arguments when you create instances. Whether you call BaseClass.__init__ early or late in the subclass init method could depend on what your classes are doing. Remember, in Python, __init__ only initializes objects, it doesn't create them. It's just another bit of code that you can call whenever you want. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] kwargs to object proporties?
Hello, What's the best way convert keyword arguments to object properties? Basically, I have a defined list of valid object properties that I'd like to optionally specify in the call to the constructor. I've got ideas about using __getattr__ but I'm not sure if that's the right way. Plus, that kind of makes it hard to use tab completion of objects in iPython. Thanks, :) Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Calling super classs __init__?
Hello, Now, perhaps this not the best way write code, but I have a few questions regrading calling the super classes constructor: I have a super class that accepts many arguments to it's constructor, and a subclass that should define one additional argument. What's the most "pythonic" way to make this work? class MySuperClass(object): def __init__(self, opt_1, opt_2, opt_3, opt_n): # stuff done here pass class MySubClass(MySuperClass): def __init__(self, just_a_sub_option): # what about other args? **args? # do stuff with "just_a_sub_option" MySuperClass.__init__()# Should this be first? What args to use? **args? pass Basically, I'd like to avoid maintaining a verbose list of arguments in the subclass. Thanks, :) Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] my first project: a multiplication trainer
Guba ha scritto: > I was unable to find information on tuple(). (The Python help function > was rather conservative in its output, Google not helpful). > What exactly is the use of tuple(q) here, and why does not a simple q > instead of tuple(q) do? The latter would have been my intuitive > expectation... The print statement "%dx%d = " needs a tuple of arguments. The tuple() command, that converts a list or a set of values in a tuple of values, prevent that error (for example, if the list of values is a list o of list, the print statemnte returns the error "TypeError: in argument reguired"). For example: >>>a = [[1, 2], [3, 4]] # a is a list of lists with 2 values >>>type(a[0]) >>>type(tuple(a[0])) Or: >>>a = [(1, 2), (3, 4)] # a is a list of tuples with 2 values >>>type(a[0]) > The other thing I have on my mind is this: how could I have the program > ask the math questions not horizontally but vertically? An example: > > 4 > x7 > = Simply insert a \n in the print statement, like this: print "%d\nx%d\n = " Simone Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Welcome to the "Tutor" mailing list (Digest mode)
[EMAIL PROTECTED] wrote: Welcome to the Tutor@python.org mailing list! This list is for folks who want to ask (and/or answer) questions from folks who wish to learn how to program with Python. Feel free to ask even the most basic of questions -- that's what the list is for! For best results when asking a question on this list: - Try to write some code to solve your problem - Show the code you have written - Describe what the code does and what you want it to do - If the code generates an error, copy and paste the entire error message, including the traceback, into your email. When replying to a posting: - Use Reply All to reply to the entire list - Don't top post - put your reply after the text to which you are replying For all posts: - Format your email as plain text, not HTML To post to this list, send your email to: tutor@python.org General information about the mailing list is at: http://mail.python.org/mailman/listinfo/tutor If you ever want to unsubscribe or change your options (eg, switch to or from digest mode, change your password, etc.), visit your subscription page at: http://mail.python.org/mailman/options/tutor/mb_shkup%40yahoo.com You can also make such adjustments via email by sending a message to: [EMAIL PROTECTED] with the word `help' in the subject or body (don't include the quotes), and you will get back a message with instructions. You must know your password to change your options (including changing the password, itself) or to unsubscribe. It is: Vizija1 Normally, Mailman will remind you of your python.org mailing list passwords once every month, although you can disable this if you prefer. This reminder will also include instructions on how to unsubscribe or change your account options. There is also a button on your options page that will email your current password to you. - Looking for last minute shopping deals? Find them fast with Yahoo! Search.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xrange
I'm not entirely sure about this, but I think for range(), the entire range of numbers is generated at one go, which could cause a slow-down. But xrange() generates the list of numbers one at a time. For a thousand, there shouldn't be much of a difference, but if you need a million or so go with xrange() Basu ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] c++::return
elis aeris wrote: > I seriously have done my homework on writing in python I wonder if I am misunderstanding your question. This is a simple question about how functions work in Python, right? Something that most every beginning tutorial covers? You wouldn't be asking here if you had done your homework. > below is a 29 kb > .py file that I wrote to do something, although you may not care what it > does Wow, that's one long function! It looks like either you don't understand what you wrote: consective_zero = 0 ## I don't know what this is or maybe someone else has commented your code? > please just tell me in plain words: how do I break function? And seriously, you'll likely get better answers, faster, when you ask better questions. It's faster, more efficient and more rewarding. A smart question also shows us that you will value the time we spend on the answer. Taking the time to formulate a smart question will often help you answer the question on your own. Actually you did find the answer on your own (assuming I understand the question and that you wrote the function yourself): 'return'. http://docs.python.org/tut/node6.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] c++::return
i was reading it the second time 6months after and in fact i am working on version 3 of it with update to functionality. (and yes, it is MY code) how do I return a function? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xrange
ok i need about 500~1000 is that ok? my pet practice works works fine with it,but what should I watch out for? sorry for double reply kent, forgot to reply all. On Tue, Mar 18, 2008 at 3:21 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > Alan Gauld wrote: > > > Add a 3rd step-value argument to range. (You don't need the xrange > > on modern versions of Python BTW) > > Only if by 'modern' you mean Python 3; on Python 2.x there is a > difference between range() and xrange(). Though for a list of 20 ints I > don't think it matters much. > > Kent > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xrange
Alan Gauld wrote: > Add a 3rd step-value argument to range. (You don't need the xrange > on modern versions of Python BTW) Only if by 'modern' you mean Python 3; on Python 2.x there is a difference between range() and xrange(). Though for a list of 20 ints I don't think it matters much. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] c++::return
"elis aeris" <[EMAIL PROTECTED]> wrote > what do I do if i want the program/function to end? > > in c++ of > > int main(){} > > I do a return 0; Actually you don;t. In your e4xample yuou just have empty braces and that will end just fine! Similarly in Python it will just silently drop off the end of the code. However if you want to return a value to the OS other than 0 you can use the exit function from the sys module. (Or raise a SystemExit exception with an argument of the required error code) sys.exit() is explained in the Simple Sequences topic of my tutorial. -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xrange
ok. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xrange
"elis aeris" <[EMAIL PROTECTED]> wrote > for x in xrange (20, 0): >print x > > this doesn't work because it goes from a big number to a small > number, which > does nothing > but what if I need the for loop to go from a big number to a small > number? Add a 3rd step-value argument to range. (You don't need the xrange on modern versions of Python BTW) If you make the step negative it will count down: >>> range(20,0,-4) [20, 16, 12, 8, 4] >>> HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python learning curve
"TFIA Consulting, Inc." <[EMAIL PROTECTED]> wrote > Your site says it should take just a "few days" to learn Python, Thats true if you are talking about the core language and a few of the most common libraries - sys, re, os, and maybe 1 or 2 more. But thats not iincluding the hundred or so other more specialised libraries, the database and web programming frameworks, a GUI toolkit etc etc. So after a few days you could write a basic Python program. You could probably also tackle a project using one specialised library such as the database API or maybe the CSV module or the socket module. > so I told these folks to give me 12 days in case I > was stupider than average. Thats probably enough to master the core and a chosen selection of modules needed for your project. But... > Here is their documentation on compiling : Pythopn is not naturally a compiled language so immediately you are into non-standard tools and libraries. You ould reasonably charge for any of these: > Building Miro Windows ¶ This seems to be the more project specific bit. > The supported Windows port of Miro is based on > Mozilla XUL Again non standard and worse, not even a commonly used library. Bybtheir own admition its not a standard Windows GUI solution because they don't like the windows look n feel - interestingly they don't seem to care that their Windows users probably do! Whatever happened to customer choice? > The XUL port of Miro is by far the most complicated and ugliest. So you can't be expected to learn it for free! > The OS X Cocoa port is simpler, and the GTK/X11 port > is by far the simplest. So two new frameworks on top of the XUL. I'd allow at least a week for any GUI framework (unless you already know the underlying framework - eg Cocoa) And its defintely not core Python. > embedding OS X's quicktime in XUL would be a very large project. So you need QT as well as GUI Cocoa. Thats another fairly big chunk of learning if you don;t already know it. And the Python wrapper on top of that. Again not standard Python and fairly advanced Cocoa. > Miro makes heavy use of Python extensions. The "few days" for Python definitely doesn't include building Python extensions. But this is sometjing that the extra for 12 days might allow to be included. So you might consider giving this for free. MSVC++ 7.1 (2003) compiler Subversion PyRex? Psyco - http://psyco.sourceforge.net/ Py2exe - http://www.py2exe.org Null Soft Installer - http://nsis.sf.net/Download The latest sqlite3.dll file from SQLite The Windows SDK 6.1 (for Vista headers) How much of the above you charge for is up to you. Arguably SVN and MSVC++ and the WinSDK could be expected knowledge from a contractor, but all the rest are definitely beyond the basic language learning for Python. Looks like you need to do some negotiating! -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] c++::return
and also, I didn't need to break function is that program, to which i am amazed of, now come to think of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with structure unpacking module
CCing the list. Please use Reply All when responding. > I am still little confused since I was under the impression, > that if a c program was able to write this binary code, > then if we know how c "packed" the data/string then > we able to decode/unpack it using python. Thats correct but you have to specify the correct decode string to match what C wrote. > Does python not know how c packs the strings? Python knows nothing about what C does its up to the programmer to tell Python how to interpret binary data. So its the programmer who must know how C stores binary strings. > Please help me understand as to why unpack works > for numbers but not for strings. It does work for strings as both Luke and I demonstrated. But you have to tell Python how long the string is. You only specified 's' so Python looked for a single byte string. You needed to specify '4s' for a 4 byte string. Let me put it this way: When you call decode you supply a pattern which struct uses to determine how many bytes it needs and how to assign those bytes to Pyhon data types Python and struct have no idea how those bytes got there they simply take the sequence of bytes and try to interpret them in the way indicated by the format string. Thus if you write an integer into a binary file you will write 4 bytes. Knowing that you can tell struct to decode that as an integer. But you could equally well tell struct to decode those same bytes as 4 characters and struct will do so, because thats what you asked for. The 4 characters will be the ASCII characters with the values of the 4 bytes making up the original number. So the onus is on you, the programmer, to know what the correct decode pattern is for each sequence of bytes read. You can find out what that pattern is and how many bytes it equates to by using things like len(), ord(), hex() etc Youcan see an example of that in my File Handling topic in my tutorial. Look at the section on struct. HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] c++::return
elis aeris wrote: > what do I do if i want the program/function to end? > > > in c++ of > > int main(){} > > I do a return 0; What have you tried in Python? How did it work and what didn't work the way you expected? What Python documentation or tutorials have you read? Maybe helpful: http://www.google.com/search?q=python+function+return http://www.google.com/search?hl=en&q=eric+smart+question ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python learning curve
I looked at the Miro gig too. Good luck! As far as "learn python in 12 days", yes and no. You can do fantastic things in that time frame with python and the standard library. I know I had completely written my first code analysis program in 2004 in that time frame just using this PDF as reference: (http://www.diveintopython.org). I see no reason you can't do that sort of thing. However, using all these complicated things at the edge of python is going to be a little tough to come up to speed on that fast, as some of the bugs you'll suffer in these edge cases will be very hard to debug without background which you will not have. If it is a "coming up to speed enough to ask intelligent questions as to why the build is failing", that's probably doable, as long as they know your background. If its being fully functional in a complex build/library environment, no way that will happen in that time frame, especially without the ability to sit down next to someone who gets it (which is the problem with doing their teleworking arrangement for you). On fixing that last issue, you could invest in Logmein.com or some CoPilot.com time to get tutelage from their more experienced developers on the arcane warnings and errors that come out of building the libraries. If you're going to try, I suggest you do the following: 1. Build a toy program/text processing utility on the command line 2. Try building a graphical utility using a prebuilt library of their graphic toolkit 3. Then try to work on the actual code base. --Michael And on whether you do it or not for freeI'd say python is the language that has the most accessible libraries I've ever seen. I literally can use any C, C++ or Fortran library with it in a couple minutes often, a couple hours if more complex. If nothing else you're going to pick up a very versatile tool, even if you don't get the gig. On Tue, Mar 18, 2008 at 4:07 PM, TFIA Consulting, Inc. <[EMAIL PROTECTED]> wrote: > > > Hi. I am doing some work for a company that uses Python for their > application. > I have never used Python before, but I have programmed for over 35 years, > maybe 12 languages including 4 assembly level. > Your site says it should take just a "few days" to learn Python, so I told > these folks to give me 12 days in case I was stupider than average. > > My question is : Who is right? A 'few days', or going thru the docs below? > (which seems a bit more complex than that). > > Is this REALLY a "few days" task to learn? Would you agree to guarantee > coming up to speed in a few days @ no charge? > > Thank you for your advice, > ...Bill Smith > > Here is their documentation on compiling : > > == > Building Miro Windows ¶ > This page documents how to build Miro for Windows. We need more brave souls > willing to help us conquer this platform. > > Getting started ¶ > The supported Windows port of Miro is based on Mozilla XUL and found in the > source:trunk/tv/platform/windows-xul directory. There's an abandoned > "native" Windows port in source:trunk/tv/platform/windows don't mess with > it. > > You may be able to find more information here: > source:trunk/tv/platform/windows-xul/setup.py > source:trunk/tv/platform/windows-xul/README > > Question : Why don't you use XUL for all platforms? ¶ > Every couple of weeks someone flames us for not using XUL on all platforms. > > The XUL port of Miro is by far the most complicated and ugliest. XUL doesn't > really do what we want to do well. It has a lot of "security" restrictions > that we have to work around. The OS X Cocoa port is simpler, and the GTK/X11 > port is by far the simplest. > > Since we have to embed all sorts of platform specific libraries, XUL's cross > platformness doesn't make porting to other platforms easier. For example, > embedding OS X's quicktime in XUL would be a very large project. > > From a UI perspective, we want a native look and feel on all of our > platforms, except Windows where we think the platform look sucks. A real > native look and feel would require lots of tweaking for GTK, and isn't even > possible on XUL/OS X. > > Compilers ¶ > Visual Studio 2003 ¶ > Miro makes heavy use of Python extensions. Python extensions compiled with a > different compiler than Python itself are not guaranteed to work. Since the > official Python distribution for Windows is compiled with Microsoft Visual > C++ 7.1 (AKA Visual C++ .NET 2003), we only support the MSVC++ 7.1 family of > compilers for official builds. Unfortunately, Microsoft has discontinued the > no-cost "Visual C++ Toolkit 2003" compiler. > > Miro also depends on Mozilla XULRunner, PyXPCOM, VLC, and other sundries. > However, building Mozilla on Win32 platforms, much less applying our > patches, is such a time consuming process that we include pre-built binaries > for these in source:trunk/dtv-binary-kit. > Unless you need to debug issues with Miro's use of Mozi
[Tutor] c++::return
what do I do if i want the program/function to end? in c++ of int main(){} I do a return 0; ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Anyone fancy giving me some tips and an expert opinion??
elis aeris wrote: > for x in xrange (20, 0): > print x > but what if I need the for loop to go from a big number to a small number? Just give a step value: for x in xrange(20, 0, -1): print x Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] xrange
x = 0 y = 0 for x in xrange (20, 0): print x this doesn't work because it goes from a big number to a small number, which does nothing but what if I need the for loop to go from a big number to a small number? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python learning curve
TFIA Consulting, Inc. wrote: > Hi. I am doing some work for a company that uses Python for their > application. > I have never used Python before, but I have programmed for over 35 > years, maybe 12 languages including 4 assembly level. > Your site says it should take just a "few days" to learn Python, so I > told these folks to give me 12 days in case I was stupider than average. > > My question is : Who is right? A 'few days', or going thru the docs > below? (which seems a *bit* more complex than that). The docs you quote have little to do with learning Python the language. They are instructions for *building* an application that "makes heavy use of Python extensions" and which, apparently, is a bit tricky to build correctly under Windows. > Is this *REALLY* a "few days" task to learn? Maybe. I wouldn't count on it. > Would *you* agree to > guarantee coming up to speed in a few days @ no charge? I might agree to spend a few days learning the *language* at no charge. I don't think I would agree to learn how to build their application at no charge. What if it was a language you know, perhaps C, and they wanted you to figure out how to build it on your own time? Doesn't seem reasonable to me. > Here is their documentation on compiling : From here: https://develop.participatoryculture.org/trac/democracy/wiki/WindowsBuildDocs Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Anyone fancy giving me some tips and an expert opinion??
i am not sure if I am still in the mailing list of tutor@python.org so please use reply all to send me a email directly please! x = 0 y = 0 for x in xrange (20, 0): print x this doesn't work because it goes from a big number to a small number, which does nothing but what if I need the for loop to go from a big number to a small number? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python learning curve
Hi. I am doing some work for a company that uses Python for their application. I have never used Python before, but I have programmed for over 35 years, maybe 12 languages including 4 assembly level. Your site says it should take just a "few days" to learn Python, so I told these folks to give me 12 days in case I was stupider than average. My question is : Who is right? A 'few days', or going thru the docs below? (which seems a bit more complex than that). Is this REALLY a "few days" task to learn? Would you agree to guarantee coming up to speed in a few days @ no charge? Thank you for your advice, ...Bill Smith Here is their documentation on compiling : == Building Miro Windows ¶ This page documents how to build Miro for Windows. We need more brave souls willing to help us conquer this platform. Getting started ¶ The supported Windows port of Miro is based on Mozilla XUL and found in the source:trunk/tv/platform/windows-xul directory. There's an abandoned "native" Windows port in source:trunk/tv/platform/windows don't mess with it. You may be able to find more information here: source:trunk/tv/platform/windows-xul/setup.py source:trunk/tv/platform/windows-xul/README Question : Why don't you use XUL for all platforms? ¶ Every couple of weeks someone flames us for not using XUL on all platforms. The XUL port of Miro is by far the most complicated and ugliest. XUL doesn't really do what we want to do well. It has a lot of "security" restrictions that we have to work around. The OS X Cocoa port is simpler, and the GTK/X11 port is by far the simplest. Since we have to embed all sorts of platform specific libraries, XUL's cross platformness doesn't make porting to other platforms easier. For example, embedding OS X's quicktime in XUL would be a very large project. >From a UI perspective, we want a native look and feel on all of our platforms, >except Windows where we think the platform look sucks. A real native look and >feel would require lots of tweaking for GTK, and isn't even possible on XUL/OS >X. Compilers ¶ Visual Studio 2003 ¶ Miro makes heavy use of Python extensions. Python extensions compiled with a different compiler than Python itself are not guaranteed to work. Since the official Python distribution for Windows is compiled with Microsoft Visual C++ 7.1 (AKA Visual C++ .NET 2003), we only support the MSVC++ 7.1 family of compilers for official builds. Unfortunately, Microsoft has discontinued the no-cost "Visual C++ Toolkit 2003" compiler. Miro also depends on Mozilla XULRunner, PyXPCOM, VLC, and other sundries. However, building Mozilla on Win32 platforms, much less applying our patches, is such a time consuming process that we include pre-built binaries for these in source:trunk/dtv-binary-kit. Unless you need to debug issues with Miro's use of Mozilla code, it's recommended that you use these binaries. Currently, the binaries included are built using Mozilla 1.8 branch. MinGW (GCC) ¶ We've putting together instructions on building Miro with free tools. The instructions for doing this are here BuildingMiroWithMinGW. We are working hard on improving these instructions. Email us if you're interested in taking this on. If you're interested in helping but are getting stuck on compiler issues, email us, and we'll do our best to help you. Eventually, we'll merge these instructions into this document. Getting dependencies and setting up the build environment ¶ As of version 0.9.6, we will be using Python 2.5. The binary kit now contains XULRunner 1.8.0.4 linked against Python 2.5. You'll need: MSVC++ 7.1 (2003) compiler Subversion Either install the one from http://tortoisesvn.tigris.org/ or the one that comes with cygwin. The Windows binary release of Python2.5 from python.org I use http://www.python.org/ftp/python/2.5/python-2.5.msi PyRex? - http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ I use http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/oldtar/Pyrex-0.9.5.1.1.tar.gz which when untarred is Pyrex-0.9.5.1a Untar the tarball and run python setup.py install. Psyco - http://psyco.sourceforge.net/ I run svn co -r42037 http://codespeak.net/svn/psyco/dist/ Be sure to run python setup.py install. Py2exe - http://www.py2exe.org I use (http://internap.dl.sourceforge.net/sourceforge/py2exe/py2exe-0.6.6.win32-py2.5.exe Null Soft Installer - http://nsis.sf.net/Download The latest sqlite3.dll file from SQLite I use http://www.sqlite.org/sqlitedll-3_5_2.zip Copy the sqlite3.dll file from the SQLite website over the one in your python directory (Usually C:\Python25\DLLs). If you forget to do this, on certain platforms your build will have this issue. http://mail.python.org/pipermail/python-list/2007-June/444281.html The Windows SDK 6.1 (for Vista headers) http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A7
Re: [Tutor] Help with a loop
PyProg PyProg wrote: > Hello, > > I have a little problem, I have two lists: > a=[1, 2, 3, 4, 5, 6] b=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] > > ... and I want to obtain: > [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', > 1), ('h', 2), ('i', 3), ('j', 4)] > > I want to obtain that with a comprehension-list. > > Lists can have dimension completely different. Here is one way using itertools.cycle() to repeat elements of a. This will return a list the same length as b, with elements of a repeated as needed: In [140]: from itertools import cycle In [141]: zip(b, cycle(a)) Out[141]: [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', 1), ('h', 2), ('i', 3), ('j', 4)] If b might sometimes be the shorter list you will have to work a little harder, perhaps cycle both lists and take the first max(len(a), len(b)) elements: In [142]: from itertools import cycle, islice, izip In [143]: list(islice(izip(cycle(b), cycle(a)), max(len(a), len(b Out[143]: [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', 1), ('h', 2), ('i', 3), ('j', 4)] Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with a loop
Assuming that len(b) > len(a): >>> zip(itertools.cycle(a), b) [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f'), (1, 'g'), (2, 'h'), (3, 'i'), (4, 'j')] Andreas Am Dienstag, den 18.03.2008, 16:23 +0100 schrieb PyProg PyProg: > Hello, > > I have a little problem, I have two lists: > > >>> a=[1, 2, 3, 4, 5, 6] > >>> b=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] > > ... and I want to obtain: > > >>> [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', > 1), ('h', 2), ('i', 3), ('j', 4)] > > I want to obtain that with a comprehension-list. > > Lists can have dimension completely different. > > Can you help me please ?. > > a+ > signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with a loop
Hello, I have a little problem, I have two lists: >>> a=[1, 2, 3, 4, 5, 6] >>> b=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] ... and I want to obtain: >>> [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', 1), ('h', 2), ('i', 3), ('j', 4)] I want to obtain that with a comprehension-list. Lists can have dimension completely different. Can you help me please ?. a+ -- http://ekd.tolosano.info ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python, wxpython and postgresql
I don't recall a modified flag on controls in wxPython. If you only want to update that which has changed, you probably have to keep a copy of the result of the query you filled the control with, and determine the change from comparing it to the current state of the control. These guys may have something more sophisticated: http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi/11 --Michael On Mon, Mar 17, 2008 at 7:31 PM, Bill Mais <[EMAIL PROTECTED]> wrote: > Hey, I thought programming was all about the shortcuts ;-) > > I'm sorry to not be clear. I've done several excellent python + > postgresql tutorials, but the one I have not found is wxPython + > postgresql (or any database). > > Specifically, how would you take your sql results and set the values of > your wxTextCtrls and wxListCtrls? For example if the sql select > statement returns 20 fields the function would find the wxPython > controls with the same name and set their values. > > And how would you build a sql statement with only the wxPython controls > that have been modified by the user? So if only the address field was > modified the sql would be: UPDATE table1 SET address = '123 Easy Street' > WHERE rec_id = 1 > > Thanks again, > > > Bill > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Michael Langford Phone: 404-386-0495 Consulting: http://www.RowdyLabs.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with structure unpacking module
"Alan Gauld" <[EMAIL PROTECTED]> wrote >>>>>first = struct.unpack('', '\x02\x00') >> error: unpack requires a string argument of length 4 > > And here you asked for 54 characters but only gave > it two bytes. And the two byes were 02 and 00 which > are not printable characters. Oops! This should of course have been 4 characters. And the printableness is an observation but does not have any direct effect on the viability of the operation. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with structure unpacking module
Nirmal Sakthi wrote: > I am using module struct.unpack() to decode data from a binary file, > so that I can use the value in a calculation. > > I have been able to extract an integer value. > > >>>length = struct.unpack('i', '\x9c\x00\x00\x00') > >>>length = int(length[0]) > >>>print length > 156 > > I want to be able to extract a string. > > I have tried, > > >>>first = struct.unpack('s', '\x02\x00') > >>>first = str(first[0]) > >>>print first > Traceback (most recent call last): > .. > error: unpack requires a string argument of length 1 I believe you have to provide the string length for this, like struct.unpack('2s', '\x02\x00') or something. > and, > > >>>first = struct.unpack('', '\x02\x00') > >>>first = str(first[0]) > >>>print first > Traceback (most recent call last): > .. > return o.unpack(s) > error: unpack requires a string argument of length 4 That's because \x02\x00 is only 2 characters long. You don't get direct access to the hex, just to the characters. vals = struct.unpack('cc','\x02\x00') #unpack values > > My desired result would be the string '0200'. Actually, I would like > to be able to invert the bytes to get '0002'. >>> x = ['a','b'] >>> x.reverse() >>> x ['b', 'a'] Sorry I don't have more time to explain, I have to run to class. HTH, -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with structure unpacking module
"Nirmal Sakthi" <[EMAIL PROTECTED]> wrote > I want to be able to extract a string. > > I have tried, > >>>>first = struct.unpack('s', '\x02\x00') >>>>first = str(first[0]) >>>>print first >Traceback (most recent call last): > .. >error: unpack requires a string argument of length 1 Which is correct because you asked for a string of length 1 but fed it 2 bytes >>>>first = struct.unpack('', '\x02\x00') >>>>first = str(first[0]) >>>>print first > Traceback (most recent call last): > .. > return o.unpack(s) > error: unpack requires a string argument of length 4 And here you asked for 54 characters but only gave it two bytes. And the two byes were 02 and 00 which are not printable characters. > My desired result would be the string '0200'. To get that string you would need to feed that string in: To see what that string looks like we need to use the ord() function: >>> for c in '0200': print hex(ord(c)) ... 0x30 0x32 0x30 0x30 >>> So your string needs to be: '\x30\x32\x30\x30' Now in struct: >>> struct.unpack('4s','\x30\x32\x30\x30') ('0200',) >>> > Actually, I would like to be able to invert the bytes to get '0002'. Well, in that case you ned to feed struct with 0002: >>> struct.unpack('4s','\x30\x30\x30\x32') ('0002',) >>> No magic in struct it reads out what you ask it to read from the data you give it. It makes no attempt to guess what the data means it asumes you as programmer know what the data looks like and how to interpret it properly. This of course means that when using struct to extract data you need to validate that what you got out matches what you expected to get! HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Should config file parser be in module's __init__.py
Shrutarshi Basu wrote: > I'm working on a module consisting of a number of scripts that handle > communications over a serial connection. I would like someway for the > user to be able to specify which serial port to be used based on a > config file in the same directory as the user's program. Should I > place the parsing system in the module's init.py, considering that the > port will actually be accessed by a different python script in the > same module? How could I then let the other scripts access the port > information obtained by the parser? There are several common ways to do this. - have a configuration module that parses the settings and contains the results. Modules that need access to the configuration import the config module and read its values - create a configuration object that is passed as a parameter to functions that need it, or pass individual configuration items to the functions. - create a configuration object that is stored as an attribute of a class and accessed that way Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Need help with structure unpacking module
I am using module struct.unpack() to decode data from a binary file, so that I can use the value in a calculation. I have been able to extract an integer value. >>>length = struct.unpack('i', '\x9c\x00\x00\x00') >>>length = int(length[0]) >>>print length 156 I want to be able to extract a string. I have tried, >>>first = struct.unpack('s', '\x02\x00') >>>first = str(first[0]) >>>print first Traceback (most recent call last): .. error: unpack requires a string argument of length 1 and, >>>first = struct.unpack('', '\x02\x00') >>>first = str(first[0]) >>>print first Traceback (most recent call last): .. return o.unpack(s) error: unpack requires a string argument of length 4 My desired result would be the string '0200'. Actually, I would like to be able to invert the bytes to get '0002'. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor