Re: [Tutor] Question about the memory manager
> To: tutor@python.org > From: __pete...@web.de > Date: Sun, 10 Jan 2016 18:29:06 +0100 > Subject: Re: [Tutor] Question about the memory manager > > Albert-Jan Roskam wrote: > > > Hi, > > > > 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 > > I must admit that this looks rather strange to me, but I don't see any > problem why it wouldn't work. gc.collect() only helps with circular > dependencies, and there aren't any in your "rainy day fund". > > Regarding the use of sys.excepthook I'd rather (SO voting be damned!) take > the obvious approach as suggested by Vinay Sajip, i. e. > > try: > main() > except: > # do what you have to do > > instead of rewriting the hook. If potential memory resource hogs are > confined within main() with no references from any module namespace you > should have enough memory availaible to run the except suite without the > need for a rainy day fund. If you know about a specific global name that > references a consumer of a lot of memory, an in-memory db, say, then why not > handle the memory error there or at least use it in lieu of a dedicated > dummy? I. e. > > in_memory_db = None > try: > try: > main() > finally: > del in_memory_db > except: > # do what you have to do Hi all, Thanks for your replies. Initially my main concern was to also log fatal/unhandled exceptions. The database MemoryError was also I was also an issue I was just facing, so Martelli's approach seemed nice. Meanwhile I found out I did not only delete "TOP 100" (which I used to debug my code) in my SELECT query, but also DISTINCT. After I corrected this MemoryErrors are no longer an issue with this function. :-) Still, I always wonder how close I am to a MemoryError (I am on a tiny Win 7 32 VM, with Python 2.7). I sometimes check the Task Manager to see how much RAM is in use. Is there a Python way to do something similar? Best wishes, Albert-Jan ___ 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
> From: tim.pet...@gmail.com > Date: Sun, 10 Jan 2016 10:54:10 -0600 > Subject: Re: [Tutor] Question about the memory manager > To: sjeik_ap...@hotmail.com > CC: tutor@python.org > > [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. Hi Tim, Thank you! Can you recommend a document or website that CPython's memory manager? Might be interesting and perhaps useful to know a bit more about the details. Perhaps this knowledge might sometimes help writing faster code? Best wishes, Albert-Jan PS: albertjan@debian:~$ python -c "import this" The Zen of Python, by Tim Peters ... ... There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. --> Nope not even then. Perhaps if my name were Guido? :-) ___ 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
On Wed, Jan 13, 2016 at 2:01 AM, Albert-Jan Roskam wrote: > I sometimes check the Task Manager to see how much RAM is in use. Is there a > Python way to do something similar? Use the psutil module to solve this problem across platforms. For Windows only, you can use ctypes to call GetProcessMemoryInfo. Here's a function that returns the total working set size (including shared pages) and the private working set. import ctypes from ctypes import wintypes import collections kernel32 = ctypes.WinDLL('kernel32', use_last_error=True) psapi = ctypes.WinDLL('psapi', use_last_error=True) wintypes.SIZE_T = ctypes.c_size_t class PROCESS_MEMORY_COUNTERS(ctypes.Structure): _fields_ = (('cb', wintypes.DWORD), ('PageFaultCount', wintypes.DWORD), ('PeakWorkingSetSize', wintypes.SIZE_T), ('WorkingSetSize', wintypes.SIZE_T), ('QuotaPeakPagedPoolUsage',wintypes.SIZE_T), ('QuotaPagedPoolUsage',wintypes.SIZE_T), ('QuotaPeakNonPagedPoolUsage', wintypes.SIZE_T), ('QuotaNonPagedPoolUsage', wintypes.SIZE_T), ('PagefileUsage', wintypes.SIZE_T), ('PeakPagefileUsage', wintypes.SIZE_T)) def __init__(self, *args, **kwds): super(PROCESS_MEMORY_COUNTERS, self).__init__(*args, **kwds) self.cb = ctypes.sizeof(self) class PROCESS_MEMORY_COUNTERS_EX(PROCESS_MEMORY_COUNTERS): _fields_ = (('PrivateUsage', wintypes.SIZE_T),) PPROCESS_MEMORY_COUNTERS = ctypes.POINTER(PROCESS_MEMORY_COUNTERS) def check_bool(result, func, args): if not result: raise ctypes.WinError(ctypes.get_last_error()) return args kernel32.GetCurrentProcess.restype = wintypes.HANDLE psapi.GetProcessMemoryInfo.errcheck = check_bool psapi.GetProcessMemoryInfo.argtypes = (wintypes.HANDLE, PPROCESS_MEMORY_COUNTERS, wintypes.DWORD) MemoryUsage = collections.namedtuple('MemoryUsage', 'total private') def get_memory_usage(): info = PROCESS_MEMORY_COUNTERS_EX() psapi.GetProcessMemoryInfo(kernel32.GetCurrentProcess(), ctypes.byref(info), ctypes.sizeof(info)) if info.PrivateUsage: return MemoryUsage(info.WorkingSetSize, info.PrivateUsage) else: # prior to Windows 7. return MemoryUsage(info.WorkingSetSize, info.PagefileUsage) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 12 year old starting to code
On 12/01/2016 00:11, Alan Gauld wrote: CCd to list for info On 11/01/16 22:55, Steven Molter wrote: I'm running Python 3.5.1 on windows 10. OK, It should be in C:\Python35\Lib\idelib That's not the default for 3.5, see https://docs.python.org/3/using/windows.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ 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 09/01/2016 19:54, precious akams via Tutor wrote: PLEASE I NEED A LITTLE HELP . I can figure out what Iam missing in this project Create a class called BankAccount 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? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: RE: Thread output to GUI Text Field
Hi Alan, The code is working now. Thanks, Patrycja -Original Message- From: Tutor [mailto:tutor-bounces+pniewosz=slb@python.org] On Behalf Of Alan Gauld Sent: Tuesday, January 12, 2016 11:32 AM To: tutor@python.org Subject: Re: [Tutor] Fwd: RE: Thread output to GUI Text Field On 12/01/16 09:44, Alan Gauld wrote: > You didn't mention earlier that you were using threads! > That significantly complicates matters. Apologies, I just noticed that the subject line does, although it wasn't clear that you were trying to output between threads. > I have found that I need to use slots and signal to pass data between > Threads and hence Does that mean you have solved the problem? Or are you still looking for help? If so what exactly do you want to know? Do you have some code that doesn't work for example? > class Panel(QtGui.QWidget): > def __init__(self,master,parent=None): > . > . > self.initUI() > > > def initUI(self): > #Build layout > self.tcpControlMessages = QtGui.QPlainTextEdit() > > def startThreadedProcess(self): > self. tcpControlMessage.clear() > self.thread.start() > > @QtCore.Slot() > def updateMessages(self, message): > print message > self. tcpControlMessages.appendPlainText(message) We can help with the threading aspects but for Qt specifics you will probably do better on a PyQt forum. -- Alan G Author of the Learn to Program web site https://urldefense.proofpoint.com/v2/url?u=http-3A__www.alan-2Dg.me.uk_&d=CwICAg&c=uGuXJ43KPkPWEl2imVFDmZQlhQUET7pVRA2PDIOxgqw&r=VlCD52JbZNT0daOyAL7vAA&m=9SVNfjVnnKpqs4j0eWR3Iq0mcPb4UPVzbrZzb2E_iWU&s=CI27ak-lLYWB8L1KnBOekFfqjOthWxdNFshm-EUmeRg&e= https://urldefense.proofpoint.com/v2/url?u=http-3A__www.amazon.com_author_alan-5Fgauld&d=CwICAg&c=uGuXJ43KPkPWEl2imVFDmZQlhQUET7pVRA2PDIOxgqw&r=VlCD52JbZNT0daOyAL7vAA&m=9SVNfjVnnKpqs4j0eWR3Iq0mcPb4UPVzbrZzb2E_iWU&s=QRRuN9SddMDPZUwUPEfsTRKmBoSE907XCeCbt6_2rOY&e= Follow my photo-blog on Flickr at: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.flickr.com_photos_alangauldphotos&d=CwICAg&c=uGuXJ43KPkPWEl2imVFDmZQlhQUET7pVRA2PDIOxgqw&r=VlCD52JbZNT0daOyAL7vAA&m=9SVNfjVnnKpqs4j0eWR3Iq0mcPb4UPVzbrZzb2E_iWU&s=4b3hD5aM-gpp35f9pcsAjE5a_ZyDoCaxpynaDnVo7Hc&e= ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_tutor&d=CwICAg&c=uGuXJ43KPkPWEl2imVFDmZQlhQUET7pVRA2PDIOxgqw&r=VlCD52JbZNT0daOyAL7vAA&m=9SVNfjVnnKpqs4j0eWR3Iq0mcPb4UPVzbrZzb2E_iWU&s=NKRcyXW49oaftjEi7LkjX7UPa6HL45Rzv79L6qbsQRg&e= ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 12 year old starting to code
On 13/01/16 14:51, Mark Lawrence wrote: >> OK, It should be in C:\Python35\Lib\idelib > > That's not the default for 3.5, see > https://docs.python.org/3/using/windows.html Thanks for catching that. I based it on my ActiveState 3.4 install, but... I never use the default install and usually install ActiveState rather than python.org. And I haven't moved to 3.5 yet... enough excuses? :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ 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/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. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ 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 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? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] me, my arm, my availability ...
I fell recently. Ought to be nothing, but a small chip of bone, either an existing one or one I just made is nicely wedged in the joint taking away a whole lot of the ability of my arm to rotate in the elbow joint. Or hold my arm in a position that is usual for typing. Plus, now that the sprain/swelling is more or less over, the pain, unfortunately is not. The real downside is that my typing speed is down from 135-140 wpm to 5-10 wmp. At this rate, just getting my usual work done takes overtime. Seems like surgery is needed to fix this. So I wanted you all to know, no, I haven't forgotten you and no haven't stopped caring. I have just stopped being as __capable__ if you know what I mean. Please take care of yourselves and each other. I will often be reading even if typing is more than I can do right now. Laura ps -- (recent tutor discussion) I am with Alan and not with Mark. I am happy as anything when people post their not-quite-working code for homework assignments here to tutor. They aren't lazy bastards wanting somebody to do their assignments for them, they want to learn why what they are trying to do isn't working. Sounds perfect for tutor to me. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] idle??
On 09/01/2016 10:38, Chris Warrick wrote: On 8 January 2016 at 20:07, bruce wrote: So, where does IDLE fit into this IDLE is a sad little “IDE”, which is really ugly, because it’s written in Tk. It lacks many IDE features. It comes with a really basic debugger (that doesn’t even highlight the line that is being currently executed…), function signature hinting, and some code completion. Please ignore this drivel, he's spouted this before without giving any justification. IDLE is perfectly adequate as a starter for Python. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ 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] 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] idle??
On 08/01/2016 23:42, Alan Gauld wrote: On 08/01/16 19:07, bruce wrote: Is IDLE essentially an ide for doing py dev? I see there's a windows/linux (rpms) for it. Yes, its the official IDE for Python. There is an "unofficial" version called xidle which tends to get a lot of the new stuff before it makes it into the official release. For a long time not much happened with IDLE but recently there has been a bunch of activity so I'm hopeful we may soon see some new features appearing. Did you mean http://idlex.sourceforge.net/ ? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] me, my arm, my availability ...
On 13/01/2016 20:47, Laura Creighton wrote: I fell recently. Ought to be nothing, but a small chip of bone, either an existing one or one I just made is nicely wedged in the joint taking away a whole lot of the ability of my arm to rotate in the elbow joint. Or hold my arm in a position that is usual for typing. Plus, now that the sprain/swelling is more or less over, the pain, unfortunately is not. The real downside is that my typing speed is down from 135-140 wpm to 5-10 wmp. At this rate, just getting my usual work done takes overtime. Seems like surgery is needed to fix this. So I wanted you all to know, no, I haven't forgotten you and no haven't stopped caring. I have just stopped being as __capable__ if you know what I mean. Please take care of yourselves and each other. I will often be reading even if typing is more than I can do right now. Laura ps -- (recent tutor discussion) I am with Alan and not with Mark. I am happy as anything when people post their not-quite-working code for homework assignments here to tutor. They aren't lazy bastards wanting somebody to do their assignments for them, they want to learn why what they are trying to do isn't working. Sounds perfect for tutor to me. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Hardly surprising that so many experienced Python people no longer want to give their time, as the bib fitting, spoon feeding, nappy changing politically correct nambies are taking over. Don't do any research, don't tell us your OS, don't tell us your python version, but we'll still answer your question for free. Yuck, this approach makes me puke. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 12 year old starting to code
On 13/01/2016 18:08, Alan Gauld wrote: On 13/01/16 14:51, Mark Lawrence wrote: OK, It should be in C:\Python35\Lib\idelib That's not the default for 3.5, see https://docs.python.org/3/using/windows.html Thanks for catching that. I based it on my ActiveState 3.4 install, but... I never use the default install and usually install ActiveState rather than python.org. And I haven't moved to 3.5 yet... enough excuses? :-) No, I expect accuracy on a tutor mailing list from the moderator. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Removing open bracket, content, close bracket content...
Hi,I am new to Python and trying to create a script that will remove content wrapped in brackets.For example I want to remove from each line the following:[!L] [20][!20+:2]etc But when I run my script I only get the last line of the content. It is correct as far as the output I want, but I don't understand why the other lines disappear. Here is my data: [!L]KEXITSETUP=Exit Setup[20]KEXITPSSETUP=Exit PS Setup[20]KEXITCOLSETUP=Exit Color SetupKSERVERSETUP=Server Setup[!L]KPRINTERSETUP=Printer Setup[!L]KNETWORKSETUP=Network Setup[!L]KJOBLOGSETUP=Job Log Setup[!L]KLANGUAGESETUP=Language Setup[!L]KCHANGEPASSWRD=Change Password[!L]KCLRSRVR=Clear Server[!L]KFACTORYDFLT=Factory DefaultsSETUPB1=Setup[20+:2]KPSERROR=Print to PS Error[20+:2]PSERROR=Print to PS Error[20+:2]EFPSError=Print to PS Error Here is the script I have so far (remember I am new): import re with open("lcd_eng.dct") as f: with open("out.txt", "w") as f1: for line in f: if f == 0 or not line.lstrip().startswith('#'): f1.write(line) # Converts the = sign to a , comma for generation of the .csv filef = open("out.txt",'r')filedata = f.read()f.close()newdata = filedata.replace("=",",")f = open("out2.txt",'w')f.write(newdata)f.close() # Should strip out anything [...] f1 = open("out2.txt",'r')newdata = f1.read()f1.close()newdata = re.sub(r'\[[^>]*\]', '', newdata)f1 = open("end.txt",'w')f1.write(newdata)f1.close() The output I get is only the last line of the input file. Not sure why. I know the issue is in the search and replace, but I am not sure where. Thanks for any and all help.Very much appreciated.Sam ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] idle??
>> So, where does IDLE fit into this > > IDLE is a sad little “IDE”, which is really ugly, because it’s written > in Tk. It lacks many IDE features. It comes with a really basic > debugger (that doesn’t even highlight the line that is being currently > executed…), function signature hinting, and some code completion. > > And it doesn’t even do something as basic as line numbering. Hi Chris, The quality of a beginner-level IDE might not necessarily be based on the number of features it has. For someone who's starting out, IDLE is probably fine because it gets out of your way. It lets you type programs and evaluate them. For a beginner, that might just be enough to focus on learning the language. (Aside: I've had the contrary experience with Eclipse, for example, which is as full-featured as they come, but makes me feel like I'm staring at the flight controls of a space shuttle, with all this stuff about launchers and Luna and such. I can get productive with it It takes my a long time to learn. I suppose I could say the same thing about Emacs.) That is, many features might be a *distraction* from learning to program. Tools for beginners should be measured by criteria for learning, and that might not match with the features we care about as professional developers. But maybe that's a controversial opinion. I think IDLE is ok for what it's designed for: to provide a simple, textual environment for writing and running simple Python programs. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Removing open bracket, content, close bracket content...
On 13/01/16 22:25, Sam Starfas via Tutor wrote: Hi Sam, Could you repost using plain text please? As you can see below the htnml/rich text option destroys the formatting of the data and code making it near impossible to read. > Hi,I am new to Python and trying to create a script that will remove content > wrapped in brackets.For example I want to remove from each line the > following:[!L] [20][!20+:2]etc > But when I run my script I only get the last line of the content. It is > correct as far as the output I want, but I don't understand why the other > lines disappear. > Here is my data: > [!L]KEXITSETUP=Exit Setup[20]KEXITPSSETUP=Exit PS Setup[20]KEXITCOLSETUP=Exit > Color SetupKSERVERSETUP=Server Setup[!L]KPRINTERSETUP=Printer > Setup[!L]KNETWORKSETUP=Network Setup[!L]KJOBLOGSETUP=Job Log > Setup[!L]KLANGUAGESETUP=Language Setup[!L]KCHANGEPASSWRD=Change > Password[!L]KCLRSRVR=Clear Server[!L]KFACTORYDFLT=Factory > DefaultsSETUPB1=Setup[20+:2]KPSERROR=Print toPS > Error[20+:2]PSERROR=Print toPS Error[20+:2]EFPSError=Print to >PS Error > > Here is the > script I have so far (remember I am new): > import re > with open("lcd_eng.dct") as f:with open("out.txt", "w") as f1:for > line in f:if f == 0 or not line.lstrip().startswith('#'): >f1.write(line) > # Converts the = sign to a , comma for generation of the .csv filef = > open("out.txt",'r')filedata = f.read()f.close()newdata = > filedata.replace("=",",")f = open("out2.txt",'w')f.write(newdata)f.close() > # Should strip out anything [...] f1 = open("out2.txt",'r')newdata = > f1.read()f1.close()newdata = re.sub(r'\[[^>]*\]', '', newdata)f1 = > open("end.txt",'w')f1.write(newdata)f1.close() > As a guess, the problems you are facing is probably that you are throwing away (or overwriting) the results inside a loop somewhere and only the last line gets kept. You probably need to create a list and append each result to the list. But without being able to read your code that's only a guess. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor