Re: [Tutor] Python Challenge Online - 30 Questions
On 01/03/2018 14:36, Julien Carlier wrote: Hi Tim, I didn't send this message to several groups. I sended this message to 20 people from the same group. I will take care to choose relevant groups. What is considered good form? Regards, Julien Replied off-list TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Challenge Online - 30 Questions
On 01/03/2018 13:36, Julien Carlier wrote: Cisco & Dimension Data organize a Python Challenge on EDITx. It is a good way to test your skills & have fun. [... snip ...] You've just cross-posted this to several Python mailing lists / newsgroups, some of them certainly irrelevant. This is not considered good form. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Problem in python online class
Hello everybody, I am doing a python online class and I am lost. The "teacher" is a little chaotic and doesn't provide his code, so everyone must type on their own. Now the class reached a point where I am lost. It is about doing a simple web frontend with a form and saving the data of the form to mongodb. I have the form, but can't see the result in the console. Also there is nothing in mongodb after submitting. Is anybody willing to check my code and tell me where is my mistake? I am quite new to python, but not new to programming. I am mainframe-Cobol-programmer, so the basics of programming are known by me. Thank you in advance, Kind regards, Tim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Difference between %f and %F string formatting?
[boB Stepp, on %i/%d and %f/%F] > Hmm. I'm surprised this slight distinction was worth keeping two > format codes that otherwise do the same thing. Is there an actual > need for these due to Python being implemented behind the scenes in C? The implementation is irrelevant to this. What is relevant: Python took its format-string semantics from C. Because of that alone, any deviation from what the C docs say has to have very strong justification. "It's just like C" saves us from needing to write our own mountains of tutorials and reference material. The C world - which has way more people and money supporting it - did that for us. Recall that I answered your original question by pointing to an article on the web about how this stuff works in C ;-) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Difference between %f and %F string formatting?
[boB Stepp] > My Google-fu must be weak tonight. Look here: https://en.wikipedia.org/wiki/Printf_format_string > I cannot find any discernible > difference between '%f' % and '%F' % > . Is there any or do they duplicate > functionality? If the latter, why are there two ways of doing the > same thing? They differ only in the capitalization of the strings produced for NaNs and infinities (math.nan and math.inf in Python 3). >>> "%f" % math.nan nan' >>> "%F" % math.nan NAN' >>> "%f" % math.inf inf' >>> "%F" % math.inf INF' > I had a similar question for %d and %i, but googling suggests these > are inherited from differences in handling input in the C language, > though I could not locate a Python example where there is a need for > one or the other. Are there any relevant Python examples? No difference for output in Python or in C. Python inherited its format codes from C, and so that's why Python allows both: just because C does. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Resources/Books for teaching OOP in Python and Tkinter
On 19/02/2017 16:34, Marie Shaw via Tutor wrote: I am a teacher of 16-18 year olds. Since September, my classes have been learning to program in Python, using all of the basics in console mode. I now need to teach them OOP using Python, and GUI programming using Python. Please could someone one point me in the direction of a good book, or some good teaching resources. I already have Python for the Absolute Beginner, by Michael Dawson, and Python in Easy Steps, by Michael McGrath. I like these books and have covered the relevant chapters in them. However, I need to learn more. Have you tried the Computing At School forums, Marie? (I assume you're UK-based from your address and the fact that you're teaching Python in Years 11-13). There are quite a few resources there already, but you can always start a thread in, eg, the Secondary Education forum. Here are a couple of links, but you'll need to have registered with CaS to view them. http://community.computingatschool.org.uk/search/resources?action=search=search=tkinter=%E2%9C%93 http://community.computingatschool.org.uk/forums/23 Also, see GUI Zero by a former teacher who now works with the RPi Foundation: https://codeboom.wordpress.com/2017/01/07/gui-zero-making-python-guis-really-simple/ TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Resending question with smaller file
On 13/02/2017 16:06, Lisa Hasler Waters wrote: Hello Python Tutor, We are trying to use the random function in the Tkinter module in PyCharmEDU 3.5. (on Macs running 10.11.6). However, we get a number of error messages: Here's the code: from tkinter import * import random tk = Tk() canvas = Canvas(tk, width=400, height=400) canvas.pack() def random_randrange(height): pass def random_randrange(width): pass def random_rectangle(width, height): x1 = random_randrange(width) y1 = random_randrange(height) x2 = x1 + random.randrange(width) y2 = y1 + random.randrange(height) canvas.create_rectangle(x1, y1, x2, y2) random_rectangle(400, 400) tk.mainloop() Here are the error messages: Traceback (most recent call last): File "/Users/lwaters/PycharmProjects/tkinternew/rectangles.py", line 2, in import random File "/Users/lwaters/PycharmProjects/tkinternew/random.py", line 17, in randomRects(100) File "/Users/lwaters/PycharmProjects/tkinternew/random.py", line 10, in randomRects x1 = random.randrange(150) AttributeError: module 'random' has no attribute 'randrange' You've called your own module "random.py"; call it something else TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Program won't print out in Windows 10
On 24/07/2016 16:38, Ken G. wrote: While the following program prints out fine using Python 2.7.6 in Ubuntu 14.04.4 as developed using Geany 1.23.1, same program won't print out to printer under Windows 10 Pro (64 bit). Geany uses there is version 1.28 using Python 2.7.12. I can use CTRL-P to print out the listing. Thanking you readers in advance in resolving this non Windows printing issue. Rather: user believing that what works under Linux will work under Windows issue :) You might find this page helpful: http://timgolden.me.uk/python/win32_how_do_i/print.html TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Urgent: unicode problems writing CSV file
On 08/06/2016 14:54, Alex Hall wrote: > All, > I'm working on a project that writes CSV files, and I have to get it done > very soon. I've done this before, but I'm suddenly hitting a problem with > unicode conversions. I'm trying to write data, but getting the standard > cannot encode character: ordinal not in range(128) > > I've tried > str(info).encode("utf8") > str(info).decode(utf8") > unicode(info, "utf8") > csvFile = open("myFile.csv", "wb", encoding="utf-8") #invalid keyword > argument > > What else can I do? As I said, I really have to get this working soon, but > I'm stuck on this stupid unicode thing. Any ideas will be great. Thanks. > This is a little tricky. I assume that you're on Python 2.x (since open() isn't taking an encoding). Deep in the bowels of the CSV module's C implmentation is code which converts every item in the row it's receiving to a string. (Essentially does: [str(x) for x in row]). Which will assume ascii: there's no opportunity to specify an encoding. For things whose __str__ returns something ascii-ish, that's fine. But if your data does or is likely to contain non-ascii data, you'll need to preprocess it. How you do it, and how general-purpose that approach is will depend on your data. For the purposes of discussion, let's assume your data looks like this: unicode, int, int Then your encoder could do this: def encoder_of_rows(row): return [row[0].encode("utf-8"), str(row[1]), str(row[2])] and your csv processor could do this: rows = [...] with open("filename.csv", "wb") as f: writer = csv.writer(f) writer.writerows([encoder_of_rows(row) for row in rows]) but if could be more (or less) complex than that depending on your data and how much you know about it. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Curses Module
On 15/05/2016 22:45, Rosen, Brian - 2016 wrote: > To Whom it May Concern, > > > I am a high school student currently enrolled in an Intro to Computer > Programming Class. In my current assignment, I would like to import > the curses module into either Python 2.7 or Python 3.4. However, > whenever I attempt to import it, there is an Import Error that states > "No module named '_curses'. Assuming you're on Windows, you'll need to download a 3rd party curses module, such as: http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses and install it via pip. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] using a for loop in another method
On 22/04/2016 17:08, Rene.Castillo wrote: Hi, this is my first post on this mailing list- I wanted to ask about this type of execution in python, expected output- reverse_words("This is an example!") # returns "sihT si na !elpmaxe" below is my execution, followed by another persons execution, which i dont completely understand. def reverse_words(strng): strng = strng[::-1].split(' ') strng.reverse() return ' '.join(strng) def reverse_words(s) return ' '.join(s[::-1] for s in str.split(' ')) how can a for loop be called within another method like that- and possibly what situations does this benefit i don't even know how to google this sort of thing any words are appreciated- It's tricky, isn't it? Once I give you the magic phrase, you'll find examples and explanations all over the place: list comprehension (strictly, the example you're showing is a "generator comprehension" but you'll probably get more hits for the slightly older "list comprehension"). TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python
On 19/04/2016 10:03, Alan Gauld wrote: However, for now, you probably want to use IDLE which should come with Python. (It is sometimes called Python GUI on Windows too.) You should find it under Python in your All Programs view. In any recent version of Windows (ie Vista & later) the most common way to find a program is to press the "Start" button or the "Windows" key and just start typing its name -- ie rather than actually navigating through a cascade of menus. (I think on other systems this is called a "Finder" or "Launcher" or something). In this particular case, pressing "Start/Windows" and typing "IDLE" gives -- in my case -- several options, including 3.4 64-bit etc. Hopefully, for the OP, there will be just one. The same for the getting a command prompt up: press "Start/Windows" and type "Command". Obviously it will depend on what's installed but for me the "Command Prompt" icon is the top of the resulting search list. Hope that helps people who are not used to (recent) Windows and are trying to advise novice users. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PLEASE I NEED HELP URGENTLY
On 13/01/2016 20:51, Tim Golden wrote: Speaking as the list moderator in question over there: if I might moderate Mark's well-known zeal... (Absolutely no pun intended!) TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PLEASE I NEED HELP URGENTLY
On 13/01/2016 20:44, Mark Lawrence wrote: On 13/01/2016 18:13, Alan Gauld wrote: On 13/01/16 17:53, Mark Lawrence wrote: This is beyond a joke. The main mailing list is all ready being moderated because of the constant messages asking for help on this presumably homework question. Can these be stopped at source here please? I'm not sure we should. This is the kind of thing tutor is here for. The poster has provided his code and the error and is puzzled by a very common beginners issue - the use of dunder methods. It seems like a legitimate tutor post. I fully understand the main list not wanting to take them but this feels like the right place, as far as I can tell. Quoting the main Python list On 13/01/2016 05:57, ifeanyioprah--- via Python-list wrote: [... snip yet another homework dump with one more still held in moderation ...] At this point you're basically spamming this list. I won't allow any more of your posts through unless they appear to be engaging with the help shown to you (and others?) over the last few days. TJG What do you want, blood? Speaking as the list moderator in question over there: if I might moderate Mark's well-known zeal... What started as a somewhat naive but fairly typical request for coursework-style help turned into an untenable situation with the OP (or apparently several OPs, some or all possibly sock-puppets) repeating variants on the same question or simple pleas for help again and again without apparently engaging with any of the help they were receiving. What you choose to do on the Tutor list is entirely up to you. For now, on the main python-list, I've held the most egregious email address offenders for moderation. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about the memory manager
[Albert-Jan Roskam] > I just found a neat trick to free up an emergency stash of memory in > a funtion that overrides sys.excepthook. The rationale is that all > exceptions, including MemoryErrors will be logged. > The code is below. My question: is that memory *guaranteed* to be > freed right after the 'del' statement? Or should one call gc.collect to > be really sure? > > rainydayfund = [[] for x in xrange(16*1024)] # or however much you need > def handle_exception(e): > global rainydayfund > del rainydayfund > ... etc, etc ... > http://stackoverflow.com/questions/1235349/python-how-can-i-handle-any-unhandled-exception-in-an-alternative-way This works fine in all versions of CPython (the C implementation of Python distributed by python.org) to date. That's because: 1. All versions of CPython rely primarily on reference counting (`gc` is only needed to reclaim garbage containing reference cycles). An object is released immediately when its reference count falls to 0. 2. There is only one reference to the big list there (via the global `raindydayfund`), so the memory becomes garbage immediately upon executing the `del`. 3. Similarly, that giant list holds the only references to the masses of distinct empty lists it contains, so they also become garbage immediately upon the giant list becoming garbage. 4. CPython doesn't happen to stick garbage lists in, e.g., some internal free list reusable only for new list objects - it actually releases the memory for garbage lists. Kinda ;-) #2 and #3 are necessarily true. #1 is true in CPython, but not in all implementations of Python. #4 is where things _might_ change even in CPython, but it's very unlikely to change. As is, it would take a small book to flesh out what "Kinda ;-)" means, exactly. Memory management is complex, with many layers, involving many details. If you can live with all that, I'd suggest a more straightforward way of setting it up, like: rainydayfund = b"x" * N where `N` is the number of bytes you want to reserve. That is, create a giant bytestring containing the number of "emergency bytes" you need. If N is large enough, that will avoid CPython's "small object allocator" and CPython's "arena allocator", getting the memory directly from (and returning the memory directly to) the OS. The fewer layers that get involved, the fewer layers that _may_ surprise you by changing behavior in the future. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] indent error on if/elif/else
On 10/09/2015 16:38, richard kappler wrote: > Here's my code, no tabs were used, all whitespace verified made with > spacebar: > > print("Please enter a number for feed speed...") > print("1 - Batch") > print("2 - 2 per second") > print("3 - Real Time") > print("4 - Exit") > > if x == ord('1'): > delay = 0 > elif x == ord('2'): > delay = 0.5 > elif x == ord('3'): > # set delay real time > # read timestamp from line, create an offset > # send lin iaw server time with offset > else: > print("bad choice, exiting") > os.exit() > > # > > Here's the Traceback: > > File "dataFeedTest.py", line 44 > else: >^ > IndentationError: expected an indented block > > > Not a clue why it's doing this. Any help? Because the comments don't qualify as a statement. You need to have at least a "pass" in there. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] testing, please disregard
I have had some problems with another python.org ML. I am sending this to see if it is received. Please disregard. thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Functional Programming in Python
* WolfRage wolfrage8...@gmail.com [150402 11:45]: On 04/02/2015 03:08 PM, Tim Johnson wrote: SNIP You have already received valuable replies from two advanced python experts. If you are looking for a book (available digitally for kindle) I would recommend Guide To: Functional Python Comprehension Constructs by Matt Harrison Thanks I will look into this book. I have been reading a lot of articles on the topic lately. Harrison really focuses on List Comprehension as the idiomatic pythonist approach. He's very clear and concise as this eternal noob can readily understand him. I hope you find it edifying. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com, http://www.tj49.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Functional Programming in Python
* WolfRage wolfrage8...@gmail.com [150402 08:25]: These are just some questions that I have regarding the topic of Functional Programming. I am working towards a more functional approach to programming but acknowledge that it is far from Functional, especially since this is mostly impossible in Python. Questions: What are the best practices to create more Functional Python? What are your thoughts on Functional in Python? Currently I am re-writing functions to reduce their side effects. I am also removing the state from objects and putting it into a closure type function. However with callback based systems (GUI) this seemed impossible, so instead I am abusing a coroutine to maintain the state of the application. But is it abuse or does it seem like a good way to handle the callback system? The benefit to me at this time is limited, but any errors in state are confined to a single location, which is nice. What do you think about using a coroutine to handle state, how would you do it better in a callback based system. Thank you for your insights. You have already received valuable replies from two advanced python experts. If you are looking for a book (available digitally for kindle) I would recommend Guide To: Functional Python Comprehension Constructs by Matt Harrison -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com, http://www.tj49.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 132, Issue 51
Hi Guys, Very simple question, I imagine. this code throws of off a counter not defined error. Can you help? *def word_counter(word, string):* *counter = 0* *for item in string:* *if item == word:* *counter = counter + 1* *print counter* Thanks, Tim -- Tim Johnson pavemen...@gmail.com c. (267) 630-0369 (text is okay) f. (267) 352-6298 On Sat, Feb 21, 2015 at 5:00 AM, tutor-requ...@python.org wrote: Send Tutor mailing list submissions to tutor@python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to tutor-requ...@python.org You can reach the person managing the list at tutor-ow...@python.org When replying, please edit your Subject line so it is more specific than Re: Contents of Tutor digest... Today's Topics: 1. Re: updating a dictionary (Chris Stinemetz) 2. Re: updating a dictionary (Danny Yoo) 3. Re: subprocess outputing wrong info to command line (Steven D'Aprano) -- Message: 1 Date: Fri, 20 Feb 2015 17:47:29 -0600 From: Chris Stinemetz chrisstinem...@gmail.com To: Mark Lawrence breamore...@yahoo.co.uk Cc: tutor@python.org Subject: Re: [Tutor] updating a dictionary Message-ID: ca+hbpzjje-qztvl0hdrt_umatam7c8fwswhkod6gweetvfm...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Fri, Feb 20, 2015 at 4:51 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 20/02/2015 17:56, Chris Stinemetz wrote: Please don't top post as it makes long threads difficult if not impossible to follow, thanks. I am getting closer. I think I have figured out the logic. I just have a quick question. How do you access key:values in a nested dictionary? MOL02997_C': [{'2': '0', '7': '0', '8': '0', '9': '0'}]} say I want to access the key:value 8:0 print dict['MOL02997_C']['8'] doesn't seem to work. doesn't seem to work doesn't tell us much, so normally you would post your code and the full traceback that you get. However what you have seems to be a dictionary that you've called dict, hence overriding the Python built-in name. This isn't illegal but it's certainly frowned upon. For the key 'MOL02997_C' you have a list which holds one dict which contains a value '8' amongst others. Hence:- mystruct = {'MOL02997_C': [{'2': '0', '7': '0', '8': '0', '9': '0'}]} mystruct {'MOL02997_C': [{'7': '0', '8': '0', '2': '0', '9': '0'}]} mystruct['MOL02997_C'] [{'7': '0', '8': '0', '2': '0', '9': '0'}] mystruct['MOL02997_C'][0] {'7': '0', '8': '0', '2': '0', '9': '0'} mystruct['MOL02997_C'][0]['8'] '0' Got that? ? Thank you Mark. I understand what you are explaining to me but I am not sure why every instance of the key 8:value changes when I assign a new value to it. I am expecting only vals['KSL04523_A'][0]['8'] value to change to 55.55 but as you can see bellow all rows in the dictionary are changes for key 8: Thank you in advance vals['KSL04523_A'] [{'7': '0', '9': '0', '8': '0', '2': '0'}] vals['KSL04523_A'][0] {'7': '0', '9': '0', '8': '0', '2': '0'} vals['KSL04523_A'][0]['8'] '0' vals['KSL04523_A'][0]['8'] = 55.55 pprint.pprint(vals) {'CELL_': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04514_B': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04514_C': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04515_A': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04515_B': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04515_C': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04516_A': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04516_B': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04516_C': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04517_A': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04517_B': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04517_C': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04519_A': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04519_B': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04519_C': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04520_A': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04520_B': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04520_C': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04521_A': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04521_B': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04521_C': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}], 'KSL04523_A': [{'2': '0', '7': '0', '8': 55.55, '9': '0'}]}? -- Message: 2 Date: Fri, 20 Feb 2015 17:43:23 -0800 From: Danny Yoo d...@hashcollision.org To: Chris Stinemetz chrisstinem...@gmail.com Cc: Mark Lawrence breamore...@yahoo.co.uk, Python Tutor Mailing
Re: [Tutor] Real world experience
Probably off-topic for the list but i'll let some of the others weigh in on that. This is more for help with the python language itself. But i'll weigh in. Programming is difficult work. It's definitely a profitable career. Its hard to say how much you'll make since it varies depending on location, but in general a combination of experience and your ability to solve difficult problems and provide solutions consistently command higher salaries. However, many companies wont even consider you without a degree, or *a significant *contribution to the industry. If you want to pursue a career in IT, you need to finish high school. You would be wise to get a degree. My $0.02. Tim On Sun, May 11, 2014 at 7:12 PM, C Smith illusiontechniq...@gmail.comwrote: I have never known anyone that works in this industry. I got one job transforming xml (should have used xslt, ended up using sed and python regex scripts) where the guy asked me how much I wanted and I threw 200 bucks out there because I could get a room for two weeks at that cost. He just laughed and handed me the money. That is the only professional experience I have and no formal education whatsoever (some high school). I have been doing online stuff and hit a wall in a 'design of computer programs' class on udacity. I made it about halfway through but started back at square one to sharpen my skills before trying to come at it again from a different angle. I started to feel overwhelmed when trying to basically recode regex (functions for '*' and '.' for instance) in python and make an api to interact easily with the text parser. I am still completely in the dark about what level of difficulty I would be facing in the professional world. If this is difficult at all for me, is there hope to think about making money in this field? I am pretty persistent and can keep up a level of work if I am not even close yet, but I don't know if I am a year off or 10 years off. Are basic scripting skills employable at even a very low rate (10 bucks an hour)? What level of experience are the people at who make 100k a year? Sorry if this is off-topic for the list, but I am trying to get past a psychological hurdle or two before reapplying myself and hopefully it would be valuable to others as well. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how do i delete the questions that i asked and it has been shared in web
No. On Wed, Mar 12, 2014 at 1:33 PM, S Tareq stare...@yahoo.com wrote: so you can't delete the question that i have asked long time ago On Wednesday, 12 March 2014, 18:03, Zachary Ware zachary.ware+py...@gmail.com wrote: On Wed, Mar 12, 2014 at 12:46 PM, S Tareq stare...@yahoo.com wrote: this one http://code.activestate.com/lists/python-tutor/99408/ and there are other ones as well This is a mailing list. Once an email is sent, you can't unsend it. -- Zach ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] educational
On 09/03/2014 17:06, Alan Gauld wrote: On 09/03/14 10:37, Peter Otten wrote: In this case, I'm fairly sure the line producing this error is:: image = Image.open(logo.jpg) And Python is correct, the ‘Image’ type has no ‘open’ attribute. What There are a few things around called `Image`. The code the OP is trying to adapt probably uses the Image from the PIL: Which may lead to another issue since the OP is using Python 3.4. Is PIL available for any Python 3.x yet? And especially for 3.4? Pillow does seem to (haven't used it myself): http://pillow.readthedocs.org/en/latest/installation.html TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.path.append import python3 not working
On 05/02/2014 11:46, Ian D wrote: Ok even more strangely it is working in the original location. Am now not 100% sure that I have the folder structure correct. I will keep a eye on it. You might want to consider whether your approach is the best. One usually appends to sys.path when there's something dynamic about the location of modules (eg for a plugin mechanism). If your library modules are always in, say, d:/modules then just set up a PYTHONPATH env var with that in it; or use a .pth file in your python directory. I do the latter, altho' it's frowned upon by some for reasons I've never entirely understood. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.path.append import python3 not working
On 05/02/2014 11:58, Oscar Benjamin wrote: Another option is to place it in site-packages. If you don't want to use the system site packages you can always use the one in your user directory. In my case on Ubuntu that's in ~/.local/lib/pythonX.Y/site-packages/ Good point: I always forget the user-specific site-package. Since the OP is on Windows... on my (Windows 7) box it's: %APPDATA%\Python\Python33\site-packages TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sys.path.append import python3 not working
On 05/02/2014 11:55, Ian D wrote: The network dictates that it is the only way I can really do it as I cannot edit any files directly. I have to append the path on the fly Ok; just wanted to make sure you weren't making life more difficult for yourself than needs be. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] my modules idle doesn't list functions python3.3
On 05/02/2014 11:53, Ian D wrote: Hi In Python 2.7 If I create my own modules and call them with import sys sys.path.append(d:\modules) import myMod and use tab to autocomplete I get a list functions. myMod. if I tab this I get a list of my functions (This only works if I have ran program at least once, then it seems to have loaded the module and can display its functions) But if I use Python 3.3 It does not display the functions using autocomplete Anyone know if this is fixable? The default Python interpeter on Windows doesn't come with built-in autocomplete functionality. You're may be using an IDE or extended interpreter (including the batteries-included IDLE). Or on 2.7 you've installed the pyreadline module which I think the IPython project now maintains. You'd need to install that again for 3.x. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which computer operating system is best for Python
I would agree with David and others. For programming, a chromebook would not be a good choice because you can't install any type of development environment onto the machine itself. Get something with a big screen and, preferably a full keyboard - I'm talking full size in the sense that you have the numeric keypad to the right. Unless you look a little deeper most options available will be windows based. Not a problem - I would recommend using a piece of software called Virtualbox. It is freely available and distributed by Oracle. It will allow you to install a Linux operating system on a Virtual machine that runs within windows. While this may seem complicated to somebody without experience in this area, there are great tutorials on this and the process is much more straightforward than it was just a couple years ago. The reason I suggest Linux is because a lot of Python is used in it already. Once it's installed, you are ready to go. Also, a lot of documentation you find on how to set up and configure a Python environment assumes you are using Linux. While Windows isn't entirely dissimilar, there are a few key differences which could make it more frustrating to navigate for first time users. Plus, most popular distributions make it *very *easy to install python addons and libraries. As an ancillary benefit, your child will also be learning Linux as he learns to program. On Wed, Feb 5, 2014 at 6:35 PM, David Abbott da...@pythontoo.com wrote: On Wed, Feb 5, 2014 at 7:23 PM, Marc Tompkins marc.tompk...@gmail.com wrote: On Wed, Feb 5, 2014 at 3:18 PM, Joel Goldstick joel.goldst...@gmail.com wrote: I would get a laptop with as large a screen as you can afford. Windows or Linux. I second that emotion, and also: try out the keyboard first (or rather, have your kid try it out). We spend a lot of time on our laptops, and a badly-designed keyboard can ruin an otherwise-great machine. Yes, you can plug in an external keyboard, mouse, and monitor, but most of the time you're gonna stick with what came in the box. Make sure you won't hate it. Linux runs great on older Laptops that were the top of the line in their day, two nice examples with great keyboards are dell e6400 and ibm T61's. Linux is easy to install and set up now a days :) -- David Abbott ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getUncPath(mappedDrive)
On 29/01/2014 21:58, danz wrote: Tim. I came across your code while searching for a similar need. Your post was the best I could find on the subject. Perhaps more importantly, you showed me that going down the ctypes rabbit hole can be less intimidating than I assumed. Thanks! [The OP appears to be replying via nabble to a tutor thread from about 18 months ago. I was the person doing most of the talking hence the reply to me] My use case was a little different than the original poster's. I need to retrieve the network paths for all of the mapped drives that are currently connected. I chose a different implementation, that seems to work well. I would appreciate any comments you have on this approach. [... snip subprocess NET USE + splitlines ...] It's a perfectly reasonable approach. The usual caveats would apply: that you're at the mercy of layout changes in NET USE and of i18n changes to the OK text. But both of those are low risk and if it works for you and you're in control of your environment, then it's fine. There's something somewhat satisfying in employing the underlying API for what should be a future-proof solution, but parsing stdout is a well-established approach as well. BTW, Thank you for the information on your website. Your information and pointers to GetDriveType() and GetVolumeInformation() helped me a a lot. You're welcome. Glad it was useful. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getUncPath(mappedDrive)
On 30/01/2014 11:39, Tim Golden wrote: On 29/01/2014 21:58, danz wrote: Tim. I came across your code while searching for a similar need. Your post was the best I could find on the subject. Perhaps more importantly, you showed me that going down the ctypes rabbit hole can be less intimidating than I assumed. Thanks! [The OP appears to be replying via nabble to a tutor thread from about 18 months ago. I was the person doing most of the talking hence the reply to me] Just by way of an alternative, the code outlined here: http://timgolden.me.uk/python/win32_how_do_i/show_mapped_drives.html will produce the same effect as your parsing of the net use output. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Re: How to post: Was Re: The Charms of Gmail
* Danny Yoo d...@hashcollision.org [131223 07:48]: Would everyone mind dropping this thread, at least for a few days? As far as I can tell, there's zero Python content in it, so I'm not getting much information from it. More than that, it's affecting my morale in a fairly negative manner. Thanks. I've been on this list since 2000 or 2001. This is where I learned python and Danny has been one of my mentors. Danny's grace and tact should make his behavior a role model for the rest on this ML. Consider that what is posted to this list is archived and could go far to repesent what the poster might be as a prospective employee, mate, president, chairman of the Fed or whatever :) I hope that you all have the best holiday season possible and that you have a great New Year. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com, http://www.tj49.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Expenses
On 02/12/2013 14:49, Alan Gauld wrote: Is there any point to this random set of data? Do you have a question for us? I assumed it was a mis-posted email that should have gone to some house-share group email but instead went to python-tutor. The OP's probably lying low out of embarrassment :) TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] keyboard interrupt
On 17/10/2013 16:36, Bill wrote: I know, way late to the party... Did you try Ctrl-Break? In Windows that is usually how you interrupt a program... Take consolation from the fact that your five-month delay in replying isn't even close to the longest delay I've seen on a Python list. Someone responded, quite coherently and usefully, to a thread which fell within my area of competence. But I hadn't seen the original post go past. I queried the list as to whether there were delivery delays, and someone pointed out that the answer was responding to a post from some *six years* previously! (Which I think I'd answered at the time). TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which Python should a beginner learn?
I think it really depends on why you are learning python. For me, I'm using it primarily to supplement my tools as a system engineer. The standard version of Python that installs with nearly every server I manage is 2.7, so I decided to focus on learning 2.7 because I didn't want to be in a position where I had to install Python 3 onto every server. Now, it does look like 3 has a lot of additions that help OO type programming - so if you are learning it to write robust programs 3 might be the way to go. On Wed, Oct 2, 2013 at 8:07 PM, Joel Goldstick joel.goldst...@gmail.comwrote: On Wed, Oct 2, 2013 at 7:59 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 02/10/2013 19:50, vit...@gmx.com wrote: Which version of Python should a beginner learn? 2.x or 3.x? Python 3 is the future so learn it unless you want to use a specific library which hasn't yet been ported. While I generally agree with Mark, you might want to consider other factors. Although 3.x has been around a few years, it took a while for it to pick up steam with third party modules. In the last year, Django has started to experiment with python 3.x. The other consideration is your learning style. You can find lots of youtube videos, and text tutorials on the web to learn python. Some will suit you, some maybe not. So that might lead you to start with the python that matches the resources you prefer. At any rate, if you are just learning programming, what they have in common exceeds their differences. In the end, though Mark is probably right -- all else being equal since some language issues were revisited and made better in 3.x and 2.x will eventually become a relic (maybe in 5 or 10 years). -- Roses are red, Violets are blue, Most poems rhyme, But this one doesn't. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor -- Joel Goldstick http://joelgoldstick.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqlite3 COMMIT directive
On 01/10/2013 09:03, Alan Gauld wrote: You don't normally need to use COMMIT when programming SQLite from Python, the database starts and ends transactions automatically from within the execute() function. You only need to manually commit if you manually create the transaction using BEGIN... Not so, I'm afraid. If you want autocommit, you need to send an isolation_level of None to the .connect function. If you don't, the database will rollback any uncommitted transactions on exit. The code below will only output (1,) as that value was committed. The later row is lost when the cursor/db closes. code import os, sys import sqlite3 dbname = no-commit.db if os.path.exists(dbname): os.unlink(dbname) db = sqlite3.connect(dbname) q = db.cursor() q.execute(CREATE TABLE test(a INT)) q.execute(INSERT INTO test(a) VALUES (1)) db.commit() q.execute(INSERT INTO test(a) VALUES (2)) q.close() db.close() db = sqlite3.connect(dbname) q = db.cursor() for row in q.execute(SELECT * FROM test).fetchall(): print(row) q.close() db.close() /code ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqlite3 COMMIT directive
On 01/10/2013 11:28, Alan Gauld wrote: On 01/10/13 09:25, Tim Golden wrote: On 01/10/2013 09:03, Alan Gauld wrote: You don't normally need to use COMMIT when programming SQLite from Python, the database starts and ends transactions automatically from within the execute() function. Not so, I'm afraid. If you want autocommit, you need to send an isolation_level of None to the .connect function. Hmm, I didn't express that as I should but I was meaning within a 'with' block (which the OP was using) based on this comment in the docs: Connection objects can be used as context managers that automatically commit or rollback transactions. In the event of an exception, the transaction is rolled back; otherwise, the transaction is committed: Now I admit I didn't test it but I read that to imply that the with would autocommit. Am I mistaken? You're sort-of correct. What happens is that the database doesn't enter autocommit mode (you'll still need to specify the right isolation level on the .connect for that). Rather, the __exit__ method of the connection-as-context-manager issues the db.commit() call which will commit anything outstanding. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqlite3 COMMIT directive
On 01/10/2013 11:41, Tim Golden wrote: You're sort-of correct. What happens is that the database doesn't enter autocommit mode (you'll still need to specify the right isolation level on the .connect for that). Rather, the __exit__ method of the connection-as-context-manager issues the db.commit() call which will commit anything outstanding. Re-reading, we may be using the term autocommit in two different ways. I'm using it to refer to a database-internal option where each SQL operation is committed as soon as it completes. This mode of operation is initiated (from Python) by passing an isolation_level of None when creating the connection. The with sqlite3.connect... approach could be considered a Python-level autocommit where all the operations within the block are committed by virtue of the Python context-manager mechanism which invokes the usual database COMMIT operation on exit. In case it helps... TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] a little loop
Okay, so I made it to FOR loops in the Lutz book. A couple of days ago I was helped here with the .join method for creating strings from lists or tuples of strings. I got to wondering if I could just, for the sake of learning, do the same thing in a FOR loop, since that's today's chapter: x=0; ham=''; b=['s','p','a','m'] #or, b=('s','p','a','m') for t in b: ham=ham+b[x] print(ham);x+=1 s sp spa spam Alright, it works, eventually. Can someone help me find a little more elegant way of doing this? I'm sure there are several. Incidentally, I put the print statement within the FOR loop so I could watch progress. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] making a string
I'm new to this, just getting through the first Mark Lutz book. If I start out with : ham=list('spam');ham ['s','p','a','m'] How do I get a string back? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] making a string
On Saturday, May 25, 2013 08:31:49 pm Martin A. Brown wrote: Greetings Tim, : I'm new to this, just getting through the first Mark Lutz book. Python objects, either variables your ham below or the string 'spam' you entered manually have a specific type. Each and every variable or object has a type. I think you are trying to figure out how you started with a string that looked like 'spam' (and Python calls a type 'str') and end up with something that looks like: ['s','p','a','m'] Well, I would encourage you to play with everything at the Python prompt. You should be able to enter a tête-à-tête with Python as follows. This is what I see when I type 'python' and get an interactive console: Python 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2 Type help, copyright, credits or license for more information. Then, I can start playing with variables, strings, lists and all the other things that Mark Lutz may mention. Here's what I actually typed and what Python told me: spam = 'spam' type(spam) type 'str' ham = list(spam) type(ham) type 'list' viking = ''.join(ham) viking 'spam' type(viking) type 'str' So, the point I'm trying to make here is that you did quite a bit in just one line, by calling: ham=list('spam');ham Consider playing a bit with the interpreter. : ham=list('spam');ham : ['s','p','a','m'] : : How do I get a string back? I will now try to annotate my session above, so that you can maybe see how I was able to get a string. spam = 'spam' # -- variable spam now contains string 'spam' type(spam) type 'str' # -- and Python tells me it's a string ham = list(spam) # -- I'm running your command type(ham) type 'list' # -- Wait, what!? It's a list?! Oh. Yeah. viking = ''.join(ham) # -- create a string of the list elements viking 'spam' type(viking) # -- ah, here's our string! type 'str' Try out the .join(ham) trick with other strings. For example...what happens when you try these yourself: ham = list('spam') '-'.join(ham) ':'.join(ham) 'B'.join(ham) ''.join(ham) Hopefully, you see that there's no magic here at all--just that you have learned how create a string with all of the elements in a list. Try something else for your amusement, as well... ' '.join(list('frobnitz')) Does that make sense? Welcome to Python, and Mark Lutz has been writing books on Python for almost as long as Python has been around. So, good luck and ask questions here. There's quite a group here willing to help. -Martin The answer was to include ''.join(ham), as in making it a string method instead of a function, which doesn't exist. Thanks! For me, picking up Python is a retirement project, so no shortage of time to learn. A lot of people tend to be intimidated by Mark Lutz, and so am I, I guess. There are a lot of books out there that will get one up and running more quickly, but I get the feeling his is _complete_ instruction, not something just slopped through. Learning Python has taken a long time. I'm not sure how I'll be able to get through Programming... You'll probably see me on the Core list next year sometime. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] making a string
On Saturday, May 25, 2013 09:10:00 pm Jim Mooney wrote: On 25 May 2013 20:49, Tim Hanson tjhan...@yahoo.com wrote: A lot of people tend to be intimidated by Mark Lutz, and so am I, I guess. Interesting coincidence. This is a retirement project and I just decided on the Lutz book, which looked comprehensive, since the book I'm using is more CompSci but PyDeficient. However, the 4th edition I of Lutz that I got only goes up to Py 2.6. As a general question - is there any Big difference between 2.6 and 2.7 (the Py version I'm using) that I should look out for so I don't get tripped up? Jim Mooney Don't know. I'm reading the Kindle version that covers 3.0; before that I was playing with 2.6. Ubuntu had 3.1 in the repository, so I downloaded that, and that's what I'm using. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hard time importing a module
On 19/04/2013 16:39, eryksun wrote: On Fri, Apr 19, 2013 at 11:12 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: Did these files also come with a file called setup.py? Normally, a Python module is not installed by manually copying the files to the appropriate places but by running 'python setup.py install' in the terminal. This will compile any C code and copy files to the appropriate places. Note that you will need to have separately installed a C compiler to be able to compile C code. I think this is the SendKeys module in question: http://web.archive.org/web/20121002234104/http://www.rutherfurd.net/python/sendkeys You can get the zipped source from archive.org above, along with binaries for 2.1-2.6. The source has a setup.py, but as Oscar said already you'll need a C compiler. You can use Visual Studio 2008 to compile it for 2.6/2.7. There are direct links for VS 2008 Express edition (free as in beer) in this SO answer: As usual, the excellent Christoph Gohlke has provided binaries for a range of targets: http://www.lfd.uci.edu/~gohlke/pythonlibs/ TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hard time importing a module
On 19/04/2013 17:12, eryksun wrote: On Fri, Apr 19, 2013 at 11:52 AM, Tim Golden m...@timgolden.me.uk wrote: As usual, the excellent Christoph Gohlke has provided binaries for a range of targets: http://www.lfd.uci.edu/~gohlke/pythonlibs/ Maybe you missed the link at the end of my link fest: http://www.lfd.uci.edu/~gohlke/pythonlibs/#sendkeys Whoops. Quite right. Still, better twice than not at all ;) TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help on win32 application error
On 02/04/2013 19:19, ankesh.pra...@cognizant.com wrote: I am facing folowing erro while executing python code: Win32 exception occurred releasing IUnknown at 0x03210eb8 You need to give us a bit more of a clue as to what your code does. My guess is that you're using the pywin32 packages and, possibly, the MAPI COM interface? That occasionally throws up that sort of exception. Assuming I'm right, you're better off asking on the python-win32 mailing list, ideally with a reproducible code sample. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] There's a Programmer in Me
On 26/02/2013 13:54, Mark Lawrence wrote: On 26/02/2013 13:02, Khalid Al-Ghamdi wrote: Hi All, I'm not a programmer by profession, but I want to learn python. I've got lots of Ideas that want to realize, but I always run into these stupid hiccups where I follow the tutorials and something stupid (known/unkown) is causing things not to work ... frustration ensues... After more than 2 years (on and off) I've got the basics down and have written some scripts, but I want some place online where a live person can tutor me to the next level. Any good suggestions? As always, many thanks for your great advice. http://pythonmentors.com/ Umm. No. Sorry, Mark, but that site and the core-mentorship list it advertises are intended for progammers who want to be helped in the development *of* Python, not development *in* Python. Ie, otherwise experienced programmers who are unfamiliar with the Python codebase. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ImportError
On 31/07/2012 15:32, Tino Dai wrote: Hi All, I have been banging my head against a wall trying to figure it out. I'm getting a ImportError on a class that I know exists. I'm wondering if there is some dark corner of the import mechanism that Try running python with the -v parameter: and then from etl.transfers import eastern. That will at least confirm the file which Python is reading for the import. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Opening filenames with unicode characters
On 28/06/2012 18:19, James Chapman wrote: Hi there python list. I'm trying to open a text file named This is_a-test'FILE to Ensure$ that£ stuff^ works.txt (without the quotes) but I'm struggling to find a way to open it. Happily, you're using Windows, which makes this very much easier. Short Explanation Do this: open (ublah £3.50.txt).read () # note the u- prefix Long Explanation: There's way too many levels of indirection between you and the disk to go into it all, but basically you're telling Python to create a (byte) string from those characters using its default encoding for code, which is UTF-8. UTF-8 maps £ to the one-byte 0x9c. Somewhere in the layers between that string and the representation on disk, a mismatch occurs. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Opening filenames with unicode characters
On 28/06/2012 20:48, James Chapman wrote: The name of the file I'm trying to open comes from a UTF-16 encoded text file, I'm then using regex to extract the string (filename) I need to open. OK. Let's focus on that. For the moment -- although it might well be very relevant -- I'm going to ignore the regex side of things. It's always trying to portray things like this because there's such confusion between what characters I write to represent the data and the data represented by those characters themselves! OK, let's adopt a convention whereby I represent the data as they kind of thing you'd see in a hex editor. This obviously isn't how it appear in a a text file but hopefully it'll be clear what's going on. I have a filename £10.txt -- that is the characters: POUND SIGN DIGIT ONE DIGIT ZERO FULL STOP LATIN SMALL LETTER T LATIN SMALL LETTER X LATIN SMALL LETTER T I have -- prior to your getting there -- placed this in a text file which I guarantee is UTF16-encoded. For the purposes of illustration I shall do that in Python code here: code with open (filedata.dat, wb) as f: f.write (u£10.txt.encode (utf16)) /code The file is named filedata.dat and looks like this (per our convention): ff fe a3 00 31 00 30 00 2e 00 74 00 78 00 74 00 I now want to read the contents of the that file as a filename and open the file in question. Here goes: code # # Open the file and extract the data as a set of # bytes into a Python (byte) string. # with open(filedata.dat, rb) as f: data = f.read() # # Convert the data into a unicode object by decoding # the UTF16 bytes # filename = data.decode(utf16) # filename is now a unicode object which, depending on # what your console offers, will either display as # £10.txt or as \xa310.txt or as something else. # # Open that file by passing the unicode object directly # to Python's file-opening mechanism # ten_pound_txt = open (filename, rb) print ten_pound_txt.read () # whatever ten_pound_txt.close () /code I don't know if that makes anything clearer for you, but at least it gives you something to try out. The business with the regex clouds the issue: regex can play a little awkwardly with Unicode, so you'd have to show some code if you need help there. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing to Windows 64-bit event log
On 19/06/2012 06:37, Johan Geldenhuys wrote: I've looked all over, but couldn't find any help as far as an API goes to log to a 64-bit Windows7 machine event log. There are functions available in the pywin32 package under the win32evtlog module. I have wrapped some of them in my winsys package. Some examples here: http://winsys.readthedocs.org/en/latest/cookbook/event_logs.html TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Opensource projects / Subversion
On 08/04/2012 16:07, Steven D'Aprano wrote: mjole...@gmail.com wrote: Hey everyone, I finally made my way into working on Opensource projects. I installed tortoisesvn. I included command line tools when running the installer. However when I invoke svn at command line, I get the following error: svn: command not found It seems like svn isn't installed, but again, I had the installer include command line tools. Please help. Does this have anything to do with learning Python? What's tortoisesvn? Since you're having a problem with that, shouldn't you be asking on a tortoisesvn mailing list? As Steven points out, this is more to do with installing particular development tools that with learning Python. However... TortoiseSVN is a popular Windows Shell extension offering easy access to Subversion via Windows Explorer. Although its installers have, for a long time, only offered Shell (in the Windows sense) access to the Subversion functions, more recent installers have offered to install the commandline svn tools as well. Since I have the commandline tools already installed, I've never actually selected this option when upgrading to newer versions. So what I don't know is whether they also add a suitable directory to the PATH environment variable. But, given the message you're getting, I imagine they don't. I suspect that they would install to somewhere like: %PROGRAMFILES%\TortoiseSvn\bin You can confirm that by cut-and-pasting that into your Start Run menu or into an Explorer address bar and seeing if it comes up with a directory or not. If not, you'll have to scout around in likely places to see where it *has* installed svn.exe and its friends. Once you find them, add that directory to the PATH via: Control Panel System Advanced Environment Variables depending somewhat on what setup you're running. And then try again at the command prompt with svn. Alternatively, don't bother with the command prompt; just use TortoiseSvn natively, so to speak. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] __class__.__name__ for literal integer causes SyntaxError
See the following console session: 4.6.__class__.__name__ 'float' 6.__class__.__name__ File stdin, line 1 6.__class__.__name__ ^ SyntaxError: invalid syntax x = 6 x.__class__.__name__ 'int' me.__class__.__name__ 'str' I note that the reference to '__class__.__name__' for string and float literals is executed, but that there is a SyntaxError for that same reference of a 'int' literal. I'd welcome comments, explanations or URLs to discussions. thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] What to call a string with embedded descriptor?
This is kind of a theoretical question. I.E. I am looking for a keyword to do research on. Consider the following string: '3:2,6:2,4:3,5:0|age50height63nametimvalue' If the string above is split on the first occurance of '|', the result is a 'leftmost' component which can be decomposed into a nested list of integers which can then be used to parse the 'rightmost' string into a dictionary. What would be a generic term or a pythonist term for such a string? Thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What to call a string with embedded descriptor?
* Emile van Sebille em...@fenx.com [120330 12:21]: If the string above is split on the first occurance of '|', the result is a 'leftmost' component which can be decomposed into a nested list of integers which can then be used to parse the 'rightmost' string into a dictionary. What would be a generic term or a pythonist term for such a string? I've called them formatted or structured -- you could also say proprietary I imagine. I'm not aware if there's a formal name... Back in the day when I worked in C and did a bit of reconstructing proprietory database schemes in legacy systems, it was common for a binary file to start with a map which defined how to search the subsequent content. I never did know if there was a formal terminology for such a setup. I guess there isn't. Thanks for the reply. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Permissions Error
On 27/03/2012 05:00, Michael Lewis wrote: Traceback (most recent call last): File C:\Python27\Utilities\copyfiles.py, line 47, in module copyfiles(srcdir, dstdir) File C:\Python27\Utilities\copyfiles.py, line 42, in copyfiles shutil.copy(srcfile, dstfile) File C:\Python27\lib\shutil.py, line 116, in copy copyfile(src, dst) File C:\Python27\lib\shutil.py, line 81, in copyfile with open(src, 'rb') as fsrc: IOError: [Errno 13] Permission denied: 'C:\\Users\\Chief Ninja\\Pictures\\testdir' It's not 100% clear what's going on, but it looks as though you've passed along paths whicih result in shutil trying to open a *directory* for reading -- which it won't be able to do. (It is, in fact, possible to get a file handle to a directory on Windows but you don't want to do that and shutil doesn't know how). I've noticed that the code runs if I use shutil.copyfiles instead of shutil.copy. Do you know why? Assuming my premise above, it would be because it special-cases directories passed as parameter. (I haven't actually looked at the code to check). With this kind of problem the most helpful thing you can do for yourself -- and for us if you can't resolve it yourself -- is to pull yourself out of the depths of your copy/copyfiles architecture and to try to do a simple: open (c:/path/to/file.txt, rb) If that succeeds then obviuosly there's no permissions issue as such. If it fails (with an access error) then we're onto something. If it succeeds then, probably your more complex copyfiles code is doing something you don't think it's doing. Start chucking out print () statements or logging or something so you know *exactly* where the paths are pointing to which you're passing into the shutil or other stdlib functions. Hopefully all this will make it clearer what's going on. Full marks for posting your code -- that does help. But you'll do better if you post a *minimal* code example, and preferably a self-complete one. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getUncPath(mappedDrive)
On 25/03/2012 09:12, Albert-Jan Roskam wrote: Thank you so much for this! I think this would also be a valuable addition to os.path (where I'd expect it to be). You call WNetGetConnection twice: one time with a 'dummy' string buffer, and one time with a buffer of the exact required length. If I'd run a function getUncPath() on a gazillion paths, wouldn't it be more effcient to hard-code the length to 2048 as you suggest in your comment? The fail-and-resize-the-buffer dance is fairly common on Windows. The advantage of the technique is that it will cope with any path length. If you hardcode to 2048 (or whatever length) then the time will come when you'll encounter a longer path and then you'll have to rewrite your code with 4096 or 8192 etc. Obviously, if you have control over all the paths you're interested in, and you know that they can't grow beyond MAXLEN characters, then by all means use MAXLEN as the buffer size and shorten your code. In terms of efficiency, I imagine you'd have to run the function on an unusually high number of paths -- and you've only got 26 possible drive letters in the first place -- so it looks to me like a premature optimisation! TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getUncPath(mappedDrive)
On 24/03/2012 20:13, Albert-Jan Roskam wrote: Hi, Is there a function that takes a file path with a mapped drive (z:\blah) and returns the associated UNC path (\\server\share\ding\dang\dong\blah)? I looked in os.path, but it doesn't seem to have this. The link below seems to be a solution (code in the bottom of the page), but I can't install win32com.client in the office :-( Is there any built-in function? http://stackoverflow.com/questions/2244767/python-check-network-map There's nothing built-in. The easiest function to emulate through ctypes is probably WNetGetConnection: http://msdn.microsoft.com/en-us/library/windows/desktop/aa385453%28v=vs.85%29.aspx (this is available from pywin32 via the win32wnet package but I assume you can't install that either) TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getUncPath(mappedDrive)
On 24/03/2012 21:29, Albert-Jan Roskam wrote: Thanks! This seems a feasible approach. I have found this Python project that exposes some of the functions of mpr.dll: http://sourceforge.net/projects/wnetconnect/ WNetGetConnection is not among the functions, but the code will help. I have to read up on ctypes.Structure though as I never really understood this. This particular function call doesn't require too much work in fact. Something like the following code -- error-handling mostly omitted -- should do the trick: code import ctypes # # Get the ANSI version of the function from its DLL # WNetGetConnection = ctypes.windll.mpr.WNetGetConnectionA ERROR_MORE_DATA = 234 # # Set up the drive name to map back from # and an empty buffer with zero length. # local_name = Z: length = ctypes.c_long (0) remote_name = ctypes.create_string_buffer () # # Call the function, expecting to receive an ERROR_MORE_DATA # result, which indicates that the buffer is too small and # which populates the length field with the right length. # result = WNetGetConnection ( local_name, remote_name, ctypes.byref (length) ) # # Assuming we did get that error, recreate the buffer and # call again with the supplied length. This isn't strictly # necessary (you could probably get away with hard-coding # 2048 or whatever) but it does save you having to guess. # if result == ERROR_MORE_DATA: remote_name = ctypes.create_string_buffer (length.value) result = WNetGetConnection ( local_name, remote_name, ctypes.byref (length) ) # # If the result of either call was an error, raise an Exception # if result != 0: raise RuntimeError (Error %d % result) print Remote name is, remote_name.value /code TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which computer operating system is best for Python developers?
On 23/02/2012 09:00, Alan Gauld wrote: By no means, one of Pythons strengths is that the same code can run on many OS. But as Steven has mentioned many developers use Linux because GNU/Linux is designed as a developer's OS and comes with oodles of tools. Most of those are available for Windows too but you have to go find them, download them and install them. One thing: If you do a reinstall, download the ActiveState version rather than the Python.org version. Active state tweak their Windows version of Python to include a bunch of extra goodies for Windows programmers. Just seconding both of Alan's points here. I have been fruitfully using Python on Windows for more than 12 years now and I am one of the very few core developers who works in Windows (although sadly lacking the time at the moment to contribute much). I develop Python-based websites which run unaltered on my Win7 laptop, my WinXP desktop, and whatever flavour of Linux my hosting provider is using. (It could be RedHat or CentOS but I don't care because it just works). You need to do a very small bit of initial assumption-bashing to ensure that things will work across platforms, but once that's done you never have to change anything again. I also recommend the ActiveState distro. It sets Python up on the PATH and adds pip in the right places. Both of those are easy enough to do for yourself, but it's nice to have it done for you. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to find index of list with its value
On 08/12/2011 15:28, surya k wrote: Well, we all know to know the value when we have the index of a list. But how can we find it in the reverse way... say a listl=[1,2,3,4] l[0]=1.but how can I find its address with its value 1 ?? help ([]) ... index(...) L.index(value, [start, [stop]]) - integer -- return first index of value. Raises ValueError if the value is not present. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Handling a Unicode Return using Pyodbc
On 14/11/2011 21:43, Tony Pelletier wrote: Good Afternoon, I'm writing a program that is essentially connecting to MS SQL Server and dumping all the contents of the tables to separate csv's. I'm almost complete, but now I'm running into a Unicode issue and I'm not sure how to resolve it. I have a ridiculous amount of tables but I managed to figure out it was my Contact and a contact named Robert Bock. Here's what I caught. (127, None, u'Robert', None, u'B\xf6ck', 'uCompany Name', None, 1, 0, 327, 0) The u'B\xf6ck' is actually Böck. Notice the ö My problem is I'm not really sure how to handle it and whether or not it's failing on the query or the insert to the csv. The Exception is: 'ascii' codec can't encode character u'\xf6' in position 1: ordinal not in range(128) Thanks for producing a thinned-down example. If I may take this at face value, I assume you're doing something like this: code import csv # # Obviously from database, but for testing... # data = [ (127, None, u'Robert', None, u'B\xf6ck', 'uCompany Name', None, 1, 0, 327, 0), ] with open (temp.csv, wb) as f: writer = csv.writer (f) writer.writerows (data) /code which gives the error you describe. In short, the csv module in Python 2.x (not sure about 3.x) is unicode-unaware. You're passing it a unicode object and it's got no way of knowing what codec to use to encode it. So it doesn't try to guess: it just uses the default (ascii) and fails. And this is where it gets just a little bit messy. Depending on how much control you have over your data and how important the unicodeiness of it is, you need to encode things explicitly before they get to the csv module. One (brute force) option is this: code snippet def encoded (iterable_of_stuff): return tuple ( (i.encode (utf8) if isinstance (i, unicode) else i) for i in iterable_of_stuff ) # # ... other code # writer.writerows ([encoded (row) for row in data]) /code snippet This will encode anything unicode as utf8 and leave everything else untouched. It will slow down your csv generation, but that might well not matter (especially if you're basically IO-bound). TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Re: [python-win32] Handling a Unicode Return using Pyodbc
[cc-ing back to the *correct* list in case other readers find it helpful...] On 15/11/2011 15:16, Tony Pelletier wrote: Thanks, Tim! This is working brilliantly Slow, but working..:) I can go from here and see if there's a way to speed it up. Well you've got a few options, although an amount depends on how much control you have over your data and how well you can predict. One option is to encode at SQL Server level: CAST your NVARCHAR to VARCHAR as part of the your query, eg: SELECT contacts.id, name = CAST ( contacts.name COLLATE SQL_Latin1_General_CP1_CS_AS AS VARCHAR (200) ) FROM contacts This will bring the text in as bytes encoded Latin1 which you can then write directly to the csv without the encoder. Without having tested this, I imagine it would be faster than encoding blindly at the Python end since it'll happen lower down the stack and you're pinpointing the data rather than running through all the columns on the offchance of finding one which is unicode. An alternative is to arrange something equivalent at the Python end -- ie have specific encoders for different rows which can target the specific columns which are known to be NVARCHAR. TJG ___ python-win32 mailing list python-wi...@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GNU Emacs and Python
* Alexander Etter rhettna...@gmail.com [01 03:36]: Rinu, I use emacs. I use Python and C++. I'm also a university student. Last semester I learned python 2.7 using IDLE, and continued with IDLE while I searched for alternatives over the summer. I didn't find what I was looking for. Say, just a few weeks ago I started my C++ course and switched to emacs since the professor was using it. I tried it, read the easy to understand documentation, and I am so productive, jubilant, and satisfied with GNU Emacs. It's extensible beyond immediate comprehension; like a sunflower it starts as a seed, sprouts leaves, etc; I'm elaborating the infinite usability of emacs. My niece graduated in Computer Science at UC Berkeley. I believe that emacs was the default programming editor in many of her classes. Elisp employs docstrings for subroutines, constants and variables. Emacs has a system of extracting those docstrings, which makes any 'plugins' self documenting. I'm sure that these features make emacs very attractive for team work, regardless of the environment whether academic or professional. There is a learning curve. One may find a learning curve with everything in existence, whereas I repudiate one discouraging another for the aforementioned. Yup. Bigtime. Those who desire the power of emacs seek it. Tim, do you use GNU Emacs? I did use GNU emacs. I also used Xemacs, but prefered GNU Emacs. From what literature I've encountered including a wikipedia page I believe there is a satiric starwars-like cold-war feud between users of vi and emacs. A feud for those who have nothing better to do. The acrimony around the 'fork' of Xemacs is greater and more serious. I believe that there are 'plugins' that can make emacs easier to use for the beginner. There are also a number of emacs 'Cheat Sheets' available, perhaps even with the distro. There is a physical Reference Card available here: http://shop.fsf.org/product/emacs-reference-cards-v-22/ I highly recommend it. cheers -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 92, Issue 123
* Rinu Boney rinu.mat...@gmail.com [111031 07:03]: I Use Windows.I Already Know C/C++ which makes python syntax seem very easy. Maybe Setting Up Emacs With Python Will Make Me Productive. I Have Eclipse With PyDev. Why Is There Not A Pythonic Emacs? Rinu, by this time I believe that Alan has addressed your question above. He has also (wisely) provided caveats regarding the difficulty of learning emacs itself. I'll take a reverse of Alan's comments, not to contradict him, but to give a possible different perspective: If you learn to use emacs with python, you will essentially be learning *two* programming languages: Python _and_ elisp, which is the internal programming language of emacs. Emacs is essentially an elisp interpreter. There may be advantages to learning two languages simultaneously. This will take time. A lot of time. Do you have the time? Will you be compensated for the time? :) having two additional programming languages under your belt may be considered compensation. In case you do not know this: Emacs has the ability to run the python or language-your-choice interpreter asynchronous within the editor, in it's own window. There could be great advantages to this. I have in the past, written elisp code that allows me two write code in one window and have it evaluated in the 'python window' or 'language-of-your-choice window'. I'll reiterate what I said earlier, I no longer use emacs, but have great respect for it. I use vim linked against the python binary so that I can use python code to enhance my (hand-rolled) IDE. grin I much prefer python code to elisp code. I hope my comments are of some help. I'm sure that you have been well informed as to what you would be getting youself into. :) regards -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Setting Up Emacs
* Steven D'Aprano st...@pearwood.info [111030 07:40]: Rinu Boney wrote: I am New To Python. I Would Like To Setup Emacs As A Python IDE. I Don't Know Anything About Emacs! If you don't know anything about emacs, and you don't know anything about Python, why do you want to make things ten times more difficult by learning a new language AND the most heavyweight, complex editor at the same time? I recommend you use a more friendly editor. You haven't mentioned what operating system you are using. If you are using Linux with the KDE desktop, I recommend you use a good, modern GUI editor like Kate as your editor. Other people might prefer different editors, but I've come to like Kate the best. I've used emacs extensively in the past and now use vim. They are both rewarding to use, but to support Steven, it could be a nightmare for Rinu to to learn both python and emacs or vim. I believe that idle is part of the python distro on both linux and darwin (Mac OSX). That is worth consideration, I would think. If Rinu is on windows, there is pythonwin and there is an extremely good, well supported and easy-to-learn shareware editor called Boxer. I would recommend either to any programmer in a windows environment. Personally, I recommend against IDEs. I find that they are over-complicated and get in the way. I've seen too many people struggling because their IDE changes the way their code works. I recommend you keep your code open in an editor, an interactive session open in a good xterm, and a second xterm tab open for running your script. That's my preference. Yeah. What he said. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Setting Up Emacs
* Alan Gauld alan.ga...@btinternet.com [111030 09:26]: On 30/10/11 13:23, Rinu Boney wrote: I am New To Python. Welcome to the group. Do you know any other languages or are you new to programming as well? I Would Like To Setup Emacs As A Python IDE. I Don't Know Anything About Emacs! If you are on a Mac you can use the Apple XDeveloper tools (XCode etc) or install Eclipse. If you are not a died in the wool IDE user then try something simpler like IDLE or Pythonwin for Windows (But the fact you even mention Emacs suggests you are not using Windows) IDLE came pre-installed on my mac. I believe that I had to add it on my ubuntu PC. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end
On 29/09/2011 15:22, lina wrote: I want to read a bunch of *.doc file in present working directory, how can I use for to read one by one and do further work, sorry, what's the best reference webpage I can use? I googled, lots of distracting info, and I barely can understand how they think. Try these: http://docs.python.org/library/glob.html http://www.doughellmann.com/PyMOTW/glob/index.html TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Mac IDE
* Wayne Werner waynejwer...@gmail.com [110929 03:52]: My personal favorite? Two terminal windows - one with Vim, editing my Python scripts, and another with an interactive interpreter. Since you can map keys in Vim, I have F5 mapped to save and run current file. If you're in the habit of editing multiple files you could set it up to map F5 to ask which file you want to set as your main .py file. And since you mentioned debug, I usually just use pdb if I need debugging. You could easily map a key such as F9 to insert a new line and type 'pdb.set_trace()'. Vim has a fairly steep learning curve, but if you spend 30 minutes with the vimtutor you'll be fine. With newer versions of Vim you can also write plugins for them in Python. I'll second that. Vim (not vi - more on that later) is my IDE. I have customized it using vimscript and what I have is as feature - rich as any out-of-the-box IDE - but with differences. Of course these capabilities (and many many more) are available with Emacs. I used Emacs extensively in the past. Vim is my preference, but emacs has a feature that is not present (yet) in vim : the ability to run interpreters - as an example the terminal shell and the python - asynchronously inside of the application. This is a very handy feature, eliminating the second application window. I personally recommend that you learn one (or both) of these editors. They will highly improve the speed at which you are able to edit your code. I would not wish vim or emacs on anyone who doesn't wish to use them. But for someone with an open mind, some points : . 'vim' is not 'vi', but is 'descended from' vi. . There is 'vim' - teminal mode and 'gvim' - vim with gui. I use vim as my default midnight command editor, gvim as my 'IDE' . Emacs can be run in terminal mode also, with greater speed, but less features. . There are 'easy' modes available for both, enabling a new user to find themselves in a more familiar environment. . The python interpreter can be compiled into vim. On ubuntu it is the default. This gives the user the ability to customize vim using python code. . Some call emacs and vim 'arcane'. Some ridicule vim's 'modal' style of editing. Neither are arcane, they are very up to date and are a parallel way of doing things. vim modal editing is a thing of beauty. Watching a adept vim user work can be breathtaking to observe. The corollary would be that some consider python weird because it is column-sensitive. Just sayin' -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Mac IDE
* Alan Gauld alan.ga...@btinternet.com [110929 09:29]: On 29/09/11 12:50, Wayne Werner wrote: Two terminal windows - one with Vim, editing my Python scripts, and another with an interactive interpreter Of course these capabilities (and many many more) are available with Emacs. I personally recommend that you learn one (or both) of these editors. They will highly improve the speed at which you are able to edit your code. Unfortunately vim isn't available by default on MAcOS - at least not the last time I looked. They had elvis installed as a vi. But Emacs is there in console mode, I think you need to install X to get it in GUI mode - in which case you might as well install Emacs for Aqua... I just got a 2011 mac mini with the last OS ... time doesn't permit me to fire it up until tomorrow at the soonest, but I will report back on emacs and vim as defaults. A distribution call macvim is available and vim can also be custom built. cheers -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using xml.etree
On 19/09/2011 10:46, lists wrote: Hello again. So, any xml.etree experts out there who might have missed this over the weekend? Not me, I'm afraid, but might I suggest that you ask on the mail Python list: http://mail.python.org/mailman/listinfo/python-list There's nothing wrong with asking here, but since this question is more specific to a particular library than to Python-the-language you're more likely to find people familiar with the package (including its maintainer in fact...) TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using xml.etree
On 19/09/2011 11:01, Tim Golden wrote: you're more likely to find people familiar with the package (including its maintainer in fact...) Sorry, I misread your post and thought you were referring lxml.etree (which is a 3rd-party lib). My basic point still stands, though: you'll get more library-specific help on python-list. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Converting from a single module to a package
I'm been coding in python now for close to 10 years. one of the modules that I have composed for re-use has gotten pretty big: It is implemented as import tlib as std I am thinking about 'downsizing' this module and breaking it up into smaller components, thus a package. And I would like to do this without a lot of code revisions. I would welcome references to URLs on this topic. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Converting from a single module to a package
* Christopher King g.nius...@gmail.com [110805 12:03]: To make a package, you make a folder named what you want to name the package, for example: virus_toolkit. Then you make a file in it called __init__.py. This is what you import if you import the virus_toolkit. You usually put documentation and general functions in this I believe (I'm not 100% sure on package etiquette.) Then you put various modules inside the folder, such as brute force, worms, and Trojan_horse. Then you can do from virus_toolkit import worms, and such, or if you want to unleash a full out attack and import them all, do from virus_toolkit import *. Thanks Christopher. Your take on the issue is pretty much the same as mine. However, my question is really how to make the transition from a single module to a package with the least amount of code changes. I'm guessing that I'm going to have to bite the bullet on this one. Example: # current way import tlib as std std.htmlButton(*arglist) # New way, after transition import tlib as std std.html.button(*arglist) #OR import html from tlib html.button(*arglist) #... oh well. Probably best to leave the original as is, for backwards compatibility. cheers -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Converting from a single module to a package
* Emile van Sebille em...@fenx.com [110805 15:51]: On 8/5/2011 4:22 PM Tim Johnson said... * Christopher Kingg.nius...@gmail.com [110805 12:03]: To make a package, you make a folder named what you want to name the package, for example: virus_toolkit. Then you make a file in it called __init__.py. This is what you import if you import the virus_toolkit. You usually put documentation and general functions in this But you can provide for both methods if in tlib.__init__ you provide for backward compatibility. # current way import tlib as std std.htmlButton(*arglist) # New way, after transition import tlib as std in tlib.__init__, include the following: import html htmlButton = html.button Yes. That's what I'm talking about. Thank you Emile. :) -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python Module for Windows Active Directory
On 28/07/2011 07:28, qbits...@gmail.com wrote: Hi, Which is the best package/module in Python to work with Windows Active Directory? I may need to create multiple OUs, set different users and computers and fill their individual attributes. Later i may need to modify/delete and then may need to check them for its availability. You could try my active_directory module: http://timgolden.me.uk/python/active_directory.html although there's a much-improved version in development (and actively used here at work). If you're interested, look at: http://svn.timgolden.me.uk/active_directory/branches/rework/ TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] dummy, underscore and unused local variables
Consider the following code: for i in range(mylimit): foo() running pychecker gives me a Local variable (i) not used complaint. If I use for dummy in range(mylimit): ## or for _ in range(mylimit): I get no complaint from pychecker. I would welcome comments on best practices for this issue. NOTE: I see much on google regarding unused local variables, but I would like to see comments here specifically on the use for `range' On a related note: from the python interpreter if I do help(_) I get Help on bool object: class bool(int) | bool(x) - bool .. I'd welcome comments on this as well. :) I expect to be edified is so many ways, some of them unexpected. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] create an xls file using data from a txt file
To confirm: Python does *nothing* to convert automatically from one form of path separator to another. Windows from very early on, has accepted /-slashes as path separators to API calls. Where they don't work is: at the command shell itself presumably since slashes are commonly used to introduce options; and, sometimes, the Windows Shell API although I can't lay my hands on an example at the moment. If you were to write something in C to call CreateFile and pass a path such as c:/temp/temp.txt it would work without a problem because the Windows API accepts those kinds of paths. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] cpython
On 12/05/2011 14:10, tee chwee liong wrote: hi all, i just started python but i'm hearing there is cpython. what is it different from python? is there any tutorials i can refer. CPython is just the most common version of Python, so-called because it's written in C: the one you download from python.org. It's normally only called Cpython to distinguish it if needed from other implementations, such as Jython (Java-based), IronPython (.NET-based), PyPy (Python-based) and others. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Alternate credentials
On 04/05/2011 00:18, Alan Gauld wrote: Since its more a Windows question than a Python one I suggest you try a Windows forum. comp.python.windows might be worth a try? Or even the ctypes group? While we do have some Windows users here its not really a python nwewbie type question. True enough. I should be able to help nonetheless; but I would second the recommendation to post this kind of question to the python-win32 mailing list: http://mail.python.org/mailman/listinfo/python-win32 where you'll get the benefit of a lot more knowledge and experience in the Windows area. You could obviously achieve this *outside* Python -- ie by using RunAs to launch a process as a different user. This may or may not suit your case. If you want to do the switch from within the Python process, you'll need to use the LogonUser [1] and ImpersonateLoggedOnUser [2] APIs which are both available in the pywin32 win32security module. If you only want to make a connection under this alternative identity (and not to do anything locally) then you could connect transiently with specific credentials. To do this you'd use the WNetAddConnection family of APIs [3]. Feel free to come back (or post to the python-win32 list) for more information TJG [1] http://msdn.microsoft.com/en-us/library/aa378184%28v=vs.85%29.aspx [2] http://msdn.microsoft.com/en-us/library/aa378612%28v=vs.85%29.aspx [3] http://msdn.microsoft.com/en-us/library/aa385418%28v=vs.85%29.aspx ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Alternate credentials
On 03/05/2011 5:35 PM, Bill Allen wrote: I am needing to run a Python networked application with a specific set of credentials, Windows AD, rather than the user's own so that the app can access the needed CIFS shares. Where should I start? By saying what operating system you're running on, which will make quite a bit of difference to the answer. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] win32com and python
On 19/04/2011 15:53, Pierre Barthelemy wrote: The problem i have is that, often, while the script is running, the powerpoint file would already be open. In this case, my script would open it anew, and make the modifications in the newly opened file. To prevent that problem, i need to be able to look at the filenames of the open powerpoint files. It there a way to do that ? See if this might help (mutatis mutandis): http://timgolden.me.uk/python/win32_how_do_i/see-if-an-excel-workbook-is-open.html TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Replying
On 28/03/2011 23:17, Steven D'Aprano wrote: Corey Richardson wrote: Thunderbird has a reply list button that I use. It does? What version are you using? Also, if you're a keyboard person, Ctrl-Shift-L (Win7, TB 3.1.9) TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem recognizing '{' character?
On 29/03/2011 09:41, Peter Otten wrote: Ben Hunter wrote: Hi, I'm completing the Python lessons on YouTube that Google posted. At the end of section 2 of day 2, there is a task to identify files then put them in a zip file in any directory. The code is from the 'solution' folder, so it's not something I wrote. I suspect I have a problem with PATHS or environment variables. I'm new to programming in something as advanced as Python, but I do okay with VBA - so I just feel like there's a setting up issue somewhere. I'm on Windows 7, tried running this in Idle and from the command line. The commands module used by zip_to() is an unfortunate choice for a tutorial because it is supposed to work with unix shells only. It's also unfortunate that an issue has been outstanding here for a while: http://bugs.python.org/issue10197 It's one of those which seems simple to fix but which spawns a thousand discussions... TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CSV to Excel
On 16/03/2011 17:12, Susana Iraiis Delgado Rodriguez wrote: Thank you for your help! Once I read your comments I tried both corrections in my code, but none of them we're sucessful. Ok, Susana, your problem (here) is the use of the csv module so can I suggest we back away from your wider program and try to help you understand the way in which that works. Here's a really simple example of how to use the module: code import os import csv # # Open a file which will automatically close once # we're finished # with open (temp.csv, wb) as f: writer = csv.writer (f) # # Write to the csv file with explicit (if meaningless) strings # writer.writerow (['A', 'B', 'C']) list_of_stuff = [Name, 2, 3] # # Write something which is already a list (like your filenames) # writer.writerow (list_of_stuff) # # Now look at the contents of the file produced # print open (temp.csv).read () /code Can you run that and make sure that it produces the .csv format which you'd expect. The output should look something like this: A,B,C Name,2,3 Notice that I'm letting the csv module work out where it needs to put quote marks and where not (which is a lot of the reason for its existence). I just pass it a list of strings, numbers, or whatever and let it turn into a line. I hope that this example helps you to understand the way you would normally use the csv module. Feel free to come back to ask more questions or to see how introduce it into your wider codebase. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CSV Ouptut concern...
On 17/03/2011 11:56, Dipo Elegbede wrote: i wrote a code for extracting information from a csv file into another csv file. it worked well but i have an immediate challenge i can't seem to fix. the new file that is created has an row and then an empty row and then a row all through the file. how can i make the empty rows not be part of the file. Open the file in binary mode: fh = open('stateparty2.csv','wb') TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] atr in dir Vs. hasattr
* Steven D'Aprano st...@pearwood.info [110316 05:26]: Tim Johnson wrote: What is the difference between using hasattr(object, name) and name in dir(object) ? Did you read the Fine Manual? No but I will :) http://docs.python.org/library/functions.html#dir The default dir() mechanism behaves differently with different types of objects, as it attempts to produce the most relevant, rather than complete, information: ... Note: Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. help(dir) speaks similarly And here's an example: class C(object): ... pass ... hasattr(C, '__eq__') True '__eq__' in dir(C) False I like Wayne's approach a lot. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] atr in dir Vs. hasattr
What is the difference between using hasattr(object, name) and name in dir(object) ? TIA -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] atr in dir Vs. hasattr
This following post was originally posted to the wrong thread. I am reposting (hopefully correctly) with the first and very succint response. I thing the answer is a revealation to be noted: ## On Tue, Mar 15, 2011 at 8:00 PM, Tim Johnson t...@johnsons-web.com wrote: What is the difference between using hasattr(object, name) and name in dir(object) ## Wayne Werner waynejwer...@gmail.com Replied: ## hasattr is basically try: object.name return True except AttributeError: return False while name in dir(object) is (AFAIK) more like: for attr in dir(object): if name == attr: return True return False However, rare is the occasion that you should use either of these. If you're doing something like: if hasattr(myobj, 'something'): myobj.something() else: print blah blah blah then what you really should be doing is: try: myobj.something() except AttributeError: print blah blah blah because 1) you avoid the overhead of an extra(?) try-except block, 2) in Python it's EAFP - Easier to Ask Forgivness than Permission, 3) You shouldn't inspect an object to find out what it can do, you should just try it and then handle failures appropriately (at least that's what I've been told). YMMV, objects in mirror are closer than they appear, etc. etc. HTH, Wayne -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using the console module.
On 11/03/2011 08:12, DistortGiygas wrote: Python users, what's the best option for someone trying to emulate or use the curses module on the Windows platform? I've been fooling around with the console module: effbot.org/zone/console-handbook.htm But for the life of me, I can't figure out how to detect a KeyRelease. Could anyone share some insight, and maybe an example of how to code it? :( If your starting point is in fact curses, then you're probably better off using a curses-alike for Windows. Christopher Gohlke maintains binaries for one such: http://www.lfd.uci.edu/~gohlke/pythonlibs/ (search for curses) TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CSV to Excel
On 11/03/2011 8:59 PM, Susana Iraiis Delgado Rodriguez wrote: Hello list!! I'm trying to write a CSV file to work it with Excel. My python script is working, the issue is: when I import the file from excel the data comes with quotes at the beginnig and ending of the row. I don't want to have these quotes. What is wrong with my code? Essentially, the work is being done twice. The .writerow method expects a list which it will convert into a quoted, comma-separated string. You're giving it a list whose one element is a quoted, comma-separated string. Just pass it a list instead: writer.writerow (['Ruta', 'Archivo', '.prj']) ... writer.writerow ([filepath, filename, 1]) (BTW, my naive knowledge of Spanish suggests that you're confusing the two identical-sounding English words: root - raiz and route - ruta). TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Alternatives to pymssql to work with MS SQL Server
On 02/03/2011 09:22, Emmanuel Ruellan wrote: I installed Python 2.6 and pymssql on a machine, but as soon as I import pymssql, it crashes. It looks like this is a known problem: http://code.google.com/p/pymssql/issues/detail?id=2 What alternatives to pymssql do you recommend? I just want to be able to perform some simple queries on an MS SQL Server database. I use pyodbc: http://code.google.com/p/pyodbc/ because I tend to operate at the raw-SQL level. But if you want a rather higher-level interface then sqlalchemy is definitely your friend (which uses pyodbc under the covers by default): http://www.sqlalchemy.org/ TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Namespace variables vs. instantiation keywords - best practices
* Tim Johnson t...@johnsons-web.com [110203 10:34]: # OR (project config file) kws = load.config(myconfig,tmpl_kws) kws.update({prj:myproject,templatepath:views}) #Grr! The following line is wrong .. kws = {prj:myproject,templatepath:views} Should be #content = LoadView(**kws) sorry -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pywin32 help
On 30/01/2011 6:42 AM, walter weston wrote: hello I am running python 2.7 , I am trying to install pywin32 version 2.7 when I run the setup.py file a black console windows pops up displays some text and dissappears before I can read any of the text . I dont know what says so I cant give details here is the link to pywin32 : http://sourceforge.net/projects/pywin32/... I need pywin32 for the pythoncom module which I will be using pumpmessages .why dont they make the install easier? like a more stable EXE or something instead of all these file directories they include.. they made to make this download for an average joe haha... please help this average joe out Well it's not that hard, really: instead of going for the big green button which gives you the version-neutral source zip, just click on the link immediately to the right entitled View all files. That takes you to here: http://sourceforge.net/projects/pywin32/files/ from which you work your way down through the directories, selecting the highest number which you guess will take you to the most recent build and... voila! http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/ Lots of .exe files, one for each version of Python / processor arch. Just for the record, pywin32 has had binaries available for Python 2.7 from pretty much the day after 2.6 was released (ie long before 2.7 was officially available). TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Class Docs - how much is too much?
FYI: I'm currently using version 2.6.5 I've developed a module which necessitates a very large amount of documentation. At this point all of the documentation is in the class docstring. I'm thinking that perhaps I should pare down the docstring and deliver specific documentation topics with object methods. Example: ## Instantiation examples o.intialize() ## configuration code to copy and paste into file o.configuration() ## Internal processes o.internals() ## ... etc. ## Docstring would include instructions for implementing such ## methods. :) Perhaps there is a PEP for this and a link to such a PEP would suffice. thanks -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Print to std output with color
On 26/01/2011 6:10 PM, Scott Nelson wrote: Curses is one way to go. Another is to use the PyWin32 module discussed in this thread: http://thread.gmane.org/gmane.comp.python.tutor/58450/focus=58454 Basically, here's a snippet of code that can get you started. This requires that you have the PyWin32 module installed (already installed by default if you use ActiveState's Python distribution for Windows). Using PyWin32 isn't for the faint of heart, but it does work. import win32console handle = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE) handle.SetConsoleTextAttribute(win32console.FOREGROUND_BLUE) print 'blue text' Or use something which does it for you already: colorama -- http://tartley.com/?p=1062 TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Class Docs - how much is too much?
* Emile van Sebille em...@fenx.com [110126 12:30]: On 1/26/2011 11:03 AM Tim Johnson said... I've developed a module which necessitates a very large amount of documentation. At this point all of the documentation is in the class docstring. I'm thinking that perhaps I should pare down the docstring and deliver specific documentation topics with object ... :) Perhaps there is a PEP for this and a link to such a PEP would suffice. Yep -- google python pep docstring and you get http://www.python.org/dev/peps/pep-0257/ Thank you. That's all I need. -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing Python Script to read battery level
On 17/01/2011 03:01, FT wrote: Is there a way to read the battery level using Python? I am totally blind and want to write a script to capture the battery level and send it through the voice activeX so I can speak it... WMI should be able to query the battery information: code import wmi c = wmi.WMI () for battery in c.Win32_Battery (): print battery.Caption, battery.EstimatedChargeRemaining /code The pure-python wmi module is based here: http://timgolden.me.uk/python/wmi/index.html and can be installed via easy_install / pip. Information on the attributes of the Win32_Battery class are available here: http://msdn.microsoft.com/en-us/library/aa394074%28v=vs.85%29.aspx You might also be interested in the pyttsx project (successor to the Windows-specific pytts): http://pypi.python.org/pypi/pyttsx/1.0 although if you have existing code to work with an ActiveX control then I doubt it brings you any advantages. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Change Font Size when print to screen
On 11/01/2011 09:03, tee chwee liong wrote: When I do print Hello World, it will print to the cmd window with the standard font size. Is there a way we can increase the font size to larger when print out to the cmd window? I'm going to assume that you're using Windows, since you refer to the cmd window. If you're on Linux or OS X the answer will be different. In short, this isn't straightforward. The Python interpreter simply sends text to the console and the console renders it using whatever font and size have been selected by the user. You can set the font size of any console window (and save it as the default) by using the System Menu -- left-click at the top-left of the Window. But if you want a particular Python script to have the power to write smaller or larger text on demand, you're going to need to control the console functions directly. You can do this via the win32console module of the pywin32 modules: http://sourceforge.net/projects/pywin32/ or by rolling the same thing yourself from within Python via ctypes: http://docs.python.org/library/ctypes.html I'm not aware that you can have a mixture of smaller and larger (or different) fonts on one console window. AFAICT you can set the font/size for the whole console but nothing else. If you need more control, you're going to have to move to some kind of GUI solution. TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Named-value formatting fails
* Steven D'Aprano st...@pearwood.info [110108 19:46]: A more detailed response. Dear me... messing with globals and locals. That's always a bad sign. But let's assume this is that one time in 100 that it is actually justified... if localvals is None: self.locals = sys._getframe(1).f_locals Are you aware that this is non-portable and subject to change without notice? No! 1)Can you explain further? And you have convinced me, and furthermore given me enough to convince someone else that a different approach would be safer. 2)Can you recommend a *simple* templatting module? thanks -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Named-value formatting fails
* Steven D'Aprano st...@pearwood.info [110109 13:23]: Tim Johnson wrote: ... Are you aware that this is non-portable and subject to change without notice? No! 1)Can you explain further? . Wow! You've given me a huge amount of technical information. I can't thank you enough for the time and effort you have given this. FYI: I am adapting an old CGI-based system, much of it on a intranet to more of an MVC model. Where a complete rewrite is necessary I would probably use something like django. In this case, enormous forms (around 400 elements) are being managed. The part for which I was considering using an eval() wrapper is for relatively simple token replacement. I may get away with just using replace() or re.sub(). But first :) I must absorb and process what you have written on this subject. Thanks again -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Named-value formatting fails
I'm using 2.6.5 on ubuntu 10.04. I'm evaluating a very large string using a named-value formatting scheme. The process fails with the following error message: not enough arguments for format string In the first place, I wouldn't expect to even see this error message, because as the python documentation says: Python calls the get-item method of the right-hand-side mapping (__getitem__), when the righthand side is an instance object. As for the right-hand mapping - I'm using the following: class Evalx: def __init__(self, localvals = None, globalvals = None): if localvals is None: self.locals = sys._getframe(1).f_locals else : self.locals = locals if globalvals is None: self.globals = sys._getframe(1).f_globals else : self.globals = globals def __getitem__(self,key): return eval(key,self.globals,self.locals) the implementation looks like this: self.content = content % Evalx() I would really appreciate some insights on this issue. I don't really know how to debug this, except for to look for some %s in the `content' string. TIA -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor