Re: I need algorithm for my task
Denis McMahon writes: > On Thu, 06 Nov 2014 15:14:05 +1100, Chris Angelico wrote: > > On Thu, Nov 6, 2014 at 3:00 PM, Denis McMahon wrote: > >> def baseword(s): > >> """find shortest sequence which repeats to generate s""" > >> return s[0:["".join([s[0:x]for k in range(int(len(s)/x)+1)])[0:len > >> (s)]for x in range(1,len(s)+1)].index(s)+1] > > > > That's hardly a PEP-8 compliant line, but I can help out a bit. > > > > return s[0:[(s[0:x]*(len(s)//x+1))[0:len(s)]for x in > > range(1,len(s)+1)].index(s)+1] > > > > That's still 83 characters without indentation, but it's close now. > > l = len > r = range > > but technically then it's no longer a one liner. > > > I love the algorithm. Took me a bit of analysis (and inspection of > > partial results) to understand what your code's doing, but it's stupidly > > elegant and elegantly stupid. > > :) > > Well yes, building that list is a stupid way to solve the problem, but I > can't see another way to do it in one line. It's an implementation of my > algorithm 3 (which I think you described) but working from the other end > as it were. 70-character expression, even with the spaces: >>> x = 'tästäkötästäkötästä' >>> x[:min(k for k in range(len(x) + 1) if x == (x[:k] * len(x))[:len(x)])] 'tästäkö' -- https://mail.python.org/mailman/listinfo/python-list
RE: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
Yeah, the 11 was mesmerizing. You didn't need no stinkin' program to see how busy the system was, you just checked the lights. You could really tell when somebody was compiling or link/loading. As I've done many times since those days, I am amazed how many users could be using the system simultaneously (yes, general editing, but still...) and it wasn't a quick machine by any stretch. We had a whopping 384K memory and big multi-platter disks with a whopping 65MB. Still think in terms of PIP sometimes... Clayton >-Original Message- >From: Python-list [mailto:python-list- >bounces+crk=godblessthe...@python.org] On Behalf Of Cameron Simpson >Sent: Wednesday, November 05, 2014 2:28 PM >To: python-list@python.org >Subject: Re: [OFF-TOPIC] It is true that is impossible write in binary >code, the lowest level of programming that you can write is in hex code? > >On 05Nov2014 15:38, Denis McMahon wrote: >>On Tue, 04 Nov 2014 21:30:06 -0500, Dennis Lee Bieber wrote: >>> If you have an old system with front-panel toggle switches, you >>set the >>> switches for binary values, and then push the "enter" switch. >> >>You've booted a PDP-8 then ;) > >Not me, but I have booted a PDP-11. Same deal:-) > >Our kernels had a patch in the idle loop that updated a specific memory >address with a regularly changing bit pattern (therefore the change rate >slowed down when the machine was busy). Post boot we'd set the memory >view toggle swithces to that address and be treated to a beautiful >Cylon-like shuttling pattern of red lights indiciating business. > >Cheers, >Cameron Simpson > >The most likely way for the world to be destroyed, most experts agree, >is by accident. That's where we come in; we're computer professionals. >We cause >accidents. - Nathaniel Borenstein >-- >https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Moving a window on the screen
Hi Why the following program doesn't work ? for x in range(0, 100, 10): fen.geometry("200x200+%d+10" % x) time.sleep(0.5) where fen is a window (fen = Tk()) The fen window goes from it's initial location to the last one but we dont see all the intermediate steps thx -- https://mail.python.org/mailman/listinfo/python-list
Re: Moving a window on the screen
On Thu, Nov 6, 2014 at 7:32 PM, ast wrote: > The fen window goes from it's initial location to the last one > but we dont see all the intermediate steps You usually don't want to use time.sleep() in a GUI program. Try doing the same thing, but with an event loop delay call instead; often, the display won't update until you go back to the main loop. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Moving a window on the screen
ast wrote: > Why the following program doesn't work ? > > for x in range(0, 100, 10): > fen.geometry("200x200+%d+10" % x) > time.sleep(0.5) > > > where fen is a window (fen = Tk()) > > The fen window goes from it's initial location to the last one > but we dont see all the intermediate steps As Chris says, using sleep() with a gui program usually doesn't work. While the script is sleeping the event loop doesn't run and consequently the user will not see any updates of the program's state. Instead of sleeping you have to schedule events that trigger a callback and then go back to the event loop. Such a callback may schedule another invocation of itself, thus giving you the desired effect: import tkinter as tk root = tk.Tk() xpositions = iter(range(0, 100, 10)) def move_next(): try: x = next(xpositions) except StopIteration: pass else: root.geometry("200x200+%d+10" % x) root.after(500, move_next) # have tkinter call move_next again # in about 500 milliseconds root.after_idle(move_next) root.mainloop() -- https://mail.python.org/mailman/listinfo/python-list
Re: Moving a window on the screen
"Chris Angelico" a écrit dans le message de news:mailman.15536.1415264262.18130.python-l...@python.org... You usually don't want to use time.sleep() in a GUI program. Try doing the same thing, but with an event loop delay call instead; often, the display won't update until you go back to the main loop. Ok, thx, it works now with: import tkinter fen = tkinter.Tk() x=0 def moveW(): global x fen.geometry("200x200+%d+10" % x) x = x + 10 if (x < 1200): fen.after(50, moveW) moveW() -- https://mail.python.org/mailman/listinfo/python-list
Re: Moving a window on the screen
On 11/6/2014 3:57 AM, Chris Angelico wrote: On Thu, Nov 6, 2014 at 7:32 PM, ast wrote: The fen window goes from it's initial location to the last one but we dont see all the intermediate steps You usually don't want to use time.sleep() in a GUI program. Try doing the same thing, but with an event loop delay call instead; often, the display won't update until you go back to the main loop. import tkinter as tk root = tk.Tk() x = 0 def march(): global x print(x) root.geometry("200x200+%d+%d" % (x,x)) x += 10 if x < 200: root.after(300, march) march() root.mainloop() -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
wxPython Boxsizers
Hello, I am new to Python. I am learning boxsizer. I want to put two buttons on my panel. One at top right corner and one at bottom right corner. How do I achieve this? Thanks -- https://mail.python.org/mailman/listinfo/python-list
ANN: eGenix ThreadLock Distribution 2.13.0.1
ANNOUNCING eGenix.com ThreadLock Distribution Version 2.13.0.1 eGenix is making a ThreadLock binary distribution available to simplify the setup for users of our mxODBC Plone/Zope database adapter. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-ThreadLock-Distribution-2.13.0.1.html INTRODUCTION Several people have approached us about a problem they are facing with installing our mxODBC database adapter for Plone and Zope: http://www.egenix.com/products/zope/mxODBCZopeDA/ The adapter product has dependencies on * ThreadLock * Products.ZSQLMethods The Products.ZSQLMethods package is a pure Python package, so it installs fine on all platforms. ThreadLock comes with a Python C extension, so buildout needs to either find egg files for the platforms or have a compiler installed to build the C extensions. On Unix platforms, installing a compiler is fairly straight forward, but on Windows setting up compilers for Python is difficult and the ThreadLock entry on PyPI only comes with egg files for Python 2.6 on Windows. SOLUTION To overcome this problem, we have taken the ThreadLock package and created an internal setup to have it compiled by our build farm. You can now use these buildout configuration settings to pull the egg files from our indexes. For UCS2 Python builds (16-bit Unicode on Unix, Python for Windows): [buildout] ... find-links = ... https://downloads.egenix.com/python/index/ucs2/ eggs = ... ThreadLock [versions] ... ThreadLock = 2.13.0.1 For UCS4 Python builds (32-bit Unicode on Unix): [buildout] ... find-links = ... https://downloads.egenix.com/python/index/ucs4/ eggs = ... ThreadLock [versions] ... ThreadLock = 2.13.0.1 Available binaries -- We provide egg files for Linux x86 and x64, Windows x86 and x64 as well as the source package as fallback solution. The binaries were compiled with Python 2.4, 2.5, 2.6 and 2.7. Version number -- Note that we have added a build number to the package version. This allows us to issue updates to the package builds should these be necessary and also makes sure that your buildout will use the packages from our indexes instead of PyPI or other indexes. ABOUT THE EGENIX MXODBC PLONE/ZOPE DATABASE ADAPTER The eGenix mxODBC Zope DA allows you to easily connect your Zope or Plone CMS installation to just about any database backend on the market today, giving you the reliability of the commercially supported eGenix product mxODBC and the flexibility of the ODBC standard as middle-tier architecture. The mxODBC Zope Database Adapter is highly portable, just like Zope itself and provides a high performance interface to all your ODBC data sources, using a single well-supported interface on Windows, Linux, Mac OS X, FreeBSD and other platforms. This makes it ideal for deployment in ZEO Clusters and Zope hosting environments where stability and high performance are a top priority, establishing an excellent basis and scalable solution for your Plone CMS. Product page: http://www.egenix.com/products/zope/mxODBCZopeDA/ MORE INFORMATION For more information on the eGenix ThreadLock distribution, the eGenix mxODBC Zope DA, licensing and download instructions, please write to sa...@egenix.com. Enjoy, -- -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 06 2014) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ 2014-10-24: Released eGenix pyOpenSSL 0.13.5 ... http://egenix.com/go63 : Try our mxODBC.Connect Python Database Interface for free ! :: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- https://mail.python.org/mailman/listinfo/python-list
Re: wxPython Boxsizers
On Thu, Nov 6, 2014 at 5:13 AM, Jaydip Chakrabarty wrote: > Hello, > > I am new to Python. I am learning boxsizer. I want to put two buttons on > my panel. One at top right corner and one at bottom right corner. How do > I achieve this? > > Thanks First, what version of python. What is boxsizer? Show some code of what you have tried. > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com -- https://mail.python.org/mailman/listinfo/python-list
Re: wxPython Boxsizers
On 06/11/2014 10:13, Jaydip Chakrabarty wrote: Hello, I am new to Python. I am learning boxsizer. I want to put two buttons on my panel. One at top right corner and one at bottom right corner. How do I achieve this? Thanks Probably best asked here https://groups.google.com/forum/#!forum/wxpython-users also available as http://news.gmane.org/gmane.comp.python.wxpython -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Understanding "help" command description syntax - explanation needed
On 2014-11-06 04:05, Gene Heskett wrote: On Wednesday 05 November 2014 21:52:42 Mark Lawrence did opine And Gene did reply: On 06/11/2014 02:37, Dave Angel wrote: > Chris Angelico Wrote in message: >> On Thu, Nov 6, 2014 at 2:56 AM, Larry Martell wrote: And I don't think Larry was actually offended; it's just that some questions don't really have easy answers - imagine someone asking a great mathematician "But how do you KNOW that 2 + 2 is 4? Where's it written down?"... all he can say is "It is". >>> >>> Yeah, I'm on a lot of lists and lately I've seen a lot of 'I'm not >>> a programmer, but I want to write code and I need someone to tell >>> me how." Gets to you after a while. >> >> Too true. Those same people are unlikely to go to a gathering of >> civil engineers and say "I'm no expert, but I want to build a >> bridge and I need someone to tell me how", yet somehow it's >> expected to be possible with software. >> >> ChrisA > > Or I'm no expert but I need someone to show me how; build me one > > here in my front yard. Against a requirements specification that changes on a daily basis, I want it delivered yesterday and no you can't have any more resources to help out, so don't ask :) With, or without a toll booth and operator? Both, make it configurable. In fact, make the length configurable too, in case I want to use it across another river. -- https://mail.python.org/mailman/listinfo/python-list
Re: wxPython Boxsizers
I am using Python 2.7.6 Here is the code I am trying: import wx class MyFrame(wx.Frame): def __init__(self, *args, **kid's): wx.Frame.__init__(self, *args, **kwds) self.button_1 = wx.Button(self, wx.ID_ANY, "button_1") self.button_2 = wx.Button(self, wx.ID_ANY, "button_2") sizer_1 = wx.BoxSizer(wx.VERTICAL) sizer_1.Add(self.button_1, 0, wx.ALL | wx.ALIGN_RIGHT, 1) sizer_1.Add(self.button_2, 0, wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM, 1) self.SetSizer(sizer_1) sizer_1.Fit(self) self.Layout() if __name__ == "__main__": app = wx.PySimpleApp(0) frame_1 = MyFrame(None, wx.ID_ANY, "") frame_1.Show() app.MainLoop() Thanks. On Thursday, November 6, 2014 4:01:53 PM UTC+5:30, Joel Goldstick wrote: > On Thu, Nov 6, 2014 at 5:13 AM, Jaydip Chakrabarty > wrote: > > Hello, > > > > I am new to Python. I am learning boxsizer. I want to put two buttons on > > my panel. One at top right corner and one at bottom right corner. How do > > I achieve this? > > > > Thanks > > First, what version of python. What is boxsizer? Show some code of > what you have tried. > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > Joel Goldstick > http://joelgoldstick.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.4.2 + PyQt4 + PyCharm 3.4.1
On Saturday, November 1, 2014 3:11:54 PM UTC+3:30, Juan Christian wrote: > No one here uses PyCharm and Qt? =/ > > > On Wed, Oct 29, 2014 at 8:45 PM, Juan Christian wrote: > > It only occurs whule using PyCharm I tried it via pure terminal and > everything works... =/ > > > > > On Tue, Oct 28, 2014 at 7:45 PM, Juan Christian wrote: > > > Python 3.4.2 Windows x64 > PyQt4 4.11.2 Py3.4 Qt4.8.6 (x64) > > PyCharm 3.4.1 Pro Edition > > > > > So, PyCharm works 100% with everything here but PyQt. > > > I have this folder structure: > > > Disk C: > > PyQt4 > >> Lib/site-packages/PyQt4/(tons of files here) > > > > Python34 (normal/default installation) > > > --- > > > I tried copying the 'PyQt4' folder to my 'Python34/Lib/site-packages' folder > but when I try to code something Qt related on PyCharm I get this issue: > > > > Some skeletons failed to generate: 19 modules failed in 1 interpreter. > Details... > > > > Failed modules > > > Python 3.4.2 > PyQt4.QAxContainer > PyQt4.Qsci > PyQt4.QtCore > PyQt4.QtDeclarative > PyQt4.QtDesigner > PyQt4.QtGui > PyQt4.QtHelp > PyQt4.QtMultimedia > PyQt4.QtNetwork > PyQt4.QtOpenGL > PyQt4.QtScript > PyQt4.QtScriptTools > PyQt4.QtSql > PyQt4.QtSvg > PyQt4.QtTest > PyQt4.QtWebKit > PyQt4.QtXml > PyQt4.QtXmlPatterns > PyQt4.phonon > > > Generation of skeletons for the modules above will be tried again when the > modules are updated or a new version of generator is available. > > > And PyCharm tells me that my 'import PyQt4.ANYTHING_HERE import *' has > 'Unresolved references'. > > > --- > > > When I try to install the PyQt4 via the installer, in the default location > (C:/Python34) I get an even 'worse' error, whenever PyCharm try to update the > skeletons or something like that (that is, whenever I open a file there...), > I get tons and tons of the same error, 'Error while accessing memory at > address ', and 'python.exe' stops working. i have this problem too, and it's so annoying. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.4.2 + PyQt4 + PyCharm 3.4.1
Resolved, kinda. Just use PySide instead of PyQt. Remove everything PyQt related from PyCharm and install PySide using the PyCharm plugins window. PySide has access to all modules and packages that PyQt has, but now you need to import like "from PySide.<**> import *". On Thu, Nov 6, 2014 at 12:50 farshad akbari wrote: > On Saturday, November 1, 2014 3:11:54 PM UTC+3:30, Juan Christian wrote: > > No one here uses PyCharm and Qt? =/ > > > > > > On Wed, Oct 29, 2014 at 8:45 PM, Juan Christian > wrote: > > > > It only occurs whule using PyCharm I tried it via pure terminal and > everything works... =/ > > > > > > > > > > On Tue, Oct 28, 2014 at 7:45 PM, Juan Christian > wrote: > > > > > > Python 3.4.2 Windows x64 > > PyQt4 4.11.2 Py3.4 Qt4.8.6 (x64) > > > > PyCharm 3.4.1 Pro Edition > > > > > > > > > > So, PyCharm works 100% with everything here but PyQt. > > > > > > I have this folder structure: > > > > > > Disk C: > > > PyQt4 > > >> Lib/site-packages/PyQt4/(tons of files here) > > > > > > > Python34 (normal/default installation) > > > > > > --- > > > > > > I tried copying the 'PyQt4' folder to my 'Python34/Lib/site-packages' > folder but when I try to code something Qt related on PyCharm I get this > issue: > > > > > > > > Some skeletons failed to generate: 19 modules failed in 1 interpreter. > Details... > > > > > > > > Failed modules > > > > > > Python 3.4.2 > > PyQt4.QAxContainer > > PyQt4.Qsci > > PyQt4.QtCore > > PyQt4.QtDeclarative > > PyQt4.QtDesigner > > PyQt4.QtGui > > PyQt4.QtHelp > > PyQt4.QtMultimedia > > PyQt4.QtNetwork > > PyQt4.QtOpenGL > > PyQt4.QtScript > > PyQt4.QtScriptTools > > PyQt4.QtSql > > PyQt4.QtSvg > > PyQt4.QtTest > > PyQt4.QtWebKit > > PyQt4.QtXml > > PyQt4.QtXmlPatterns > > PyQt4.phonon > > > > > > Generation of skeletons for the modules above will be tried again when > the modules are updated or a new version of generator is available. > > > > > > And PyCharm tells me that my 'import PyQt4.ANYTHING_HERE import *' has > 'Unresolved references'. > > > > > > --- > > > > > > When I try to install the PyQt4 via the installer, in the default > location (C:/Python34) I get an even 'worse' error, whenever PyCharm try to > update the skeletons or something like that (that is, whenever I open a > file there...), I get tons and tons of the same error, 'Error while > accessing memory at address ', and 'python.exe' stops working. > > i have this problem too, > and it's so annoying. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
> On Nov 5, 2014, at 6:14 PM, Clayton Kirkwood wrote: > > Yeah, the 11 was mesmerizing. You didn't need no stinkin' program to see how > busy the system was, you just checked the lights. You could really tell when > somebody was compiling or link/loading. As I've done many times since those > days, I am amazed how many users could be using the system simultaneously > (yes, general editing, but still...) and it wasn't a quick machine by any > stretch. We had a whopping 384K memory and big multi-platter disks with a > whopping 65MB. Still think in terms of PIP sometimes… > And TECO. . . > Clayton -- https://mail.python.org/mailman/listinfo/python-list
Python has arrived!
According to http://www.theregister.co.uk/2014/11/06/hackers_use_gmail_drafts_as_dead_drops_to_control_malware_bots: "Attacks occur in two phases. Hackers first infect a targeted machine via simple malware that installs Python onto the device, [...]" -- Grant Edwards grant.b.edwardsYow! I always have fun at because I'm out of my gmail.commind!!! -- https://mail.python.org/mailman/listinfo/python-list
Re: Real-world use of Counter
On Nov 6, 2014 1:06 AM, "Rustom Mody" wrote: > In studying (somewhat theoretically) the general world of > collection data structures we see > - sets -- neither order nor repetition > - bags -- no order, repetition significant > - lists -- both order and repetition > > Sometimes 'bag' is called 'multiset' > However counter is a weird non-standard name that overloads > an already overloaded term -- 'Counter' has a very standard meaning in programming and in hardware design. "Bag" is also nonstandard. Other nonstandard names for the same type include list, heap, bunch, sample, weighted set, occurrence set and fireset. Knuth uses multiset, so let's stick with that. As for Counter already having meanings in CS, the Python Counter is compatible with those. > Calling a bag as counter is inappropriate for an analogous reason > to why calling a dictionary as a 'hash' is inappropriate -- > it confuses an implementation detail for fundamental semantics. I've never liked the term "bag". In addition to being nonstandard it's also very nonintuitive. "Multiset" is fine, except that it implies the collection is a type of set, which the Python Counter is not. The name "Counter" describes the intended use case, not the implementation, so I think it's fine. -- https://mail.python.org/mailman/listinfo/python-list
help with creating dict from string
hi, I have strings coming in with this format: '[one=two, three=four five, six, seven=eight]' and I want to create from that string, this dictionary: {'one':'two', 'three':'four five', 'six':True, 'seven':'eight'} These are option strings, with each key-value pair separated by commas. Where there is a value, the key-value pair is separated by '='. This is how I started (where s is the string): s = s.replace('[','').replace(']','') s = [x.split('=') for x in s.split(',')] [['one', 'two'], [' three', 'four five'], [' six'], [' seven', 'eight']] I know I can iterate and strip each item, fixing single-element keys as I go. I just wondered if I'm missing something more elegant. If it wasn't for the leading spaces and the boolean key, the dict() constructor would have been sweet. thanks for any ideas, --Tim -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?
On Tuesday, 4 November 2014 16:49:36 UTC, françai s wrote: > I intend to write in lowest level of computer programming as a hobby. > > It is true that is impossible write in binary code, the lowest level > of programming that you can write is in hex code? > > What is the lowest level of programming computers that you can write ? > > Is binary code? > > Is hex code? > > Is another machine code? Honestly do not know if it is true that there > is another machine code beyond the binary and hex code. > > Is Assembly? If you want a really brilliant (and simple) book about the process of designing, structuring and building programs in assembly language, I'd recommend finding a copy of a book called A Programmer's Notebook written by David M Cortesi. The context is out of date (8080/Z-80 assembly programs for CP/M), but the overall structure of each chapter is brilliant: the development of decent designs, followed by a discussion of possible approaches to programming, followed by a detailed discussion of the development of the assembly language, and finally a final assembly code listing. One advantage of this book is that the 8080/Z-80 instruction set and the interface to CP/M are both relatively simple to grasp (compared with modern CPUs and modern OSs). That said, the lessons from this book translate to any assembly programming task. Good luck. -- https://mail.python.org/mailman/listinfo/python-list
Re: help with creating dict from string
Tim wrote: > hi, I have strings coming in with this format: > > '[one=two, three=four five, six, seven=eight]' > > and I want to create from that string, this dictionary: > {'one':'two', 'three':'four five', 'six':True, 'seven':'eight'} > > These are option strings, with each key-value pair separated by commas. > Where there is a value, the key-value pair is separated by '='. > > This is how I started (where s is the string): > s = s.replace('[','').replace(']','') > s = [x.split('=') for x in s.split(',')] > > [['one', 'two'], [' three', 'four five'], [' six'], [' seven', > [['eight']] > > I know I can iterate and strip each item, fixing single-element keys as I > go. > > I just wondered if I'm missing something more elegant. If it wasn't for > the leading spaces and the boolean key, the dict() constructor would have > been sweet. Not everything has to be a one-liner ;) If it works I don't think something >>> s = '[one=two, three=four five, six, seven=eight]' >>> def fix(pair): ... key, eq, value = pair.partition("=") ... return key.strip(), value if eq else True ... >>> dict(fix(t) for t in s.strip("[]").split(",")) {'three': 'four five', 'seven': 'eight', 'one': 'two', 'six': True} is particularly inelegant. Are you sure that your grammar is not more complex than your example, e. g. that "," cannot occur in the values? -- https://mail.python.org/mailman/listinfo/python-list
Re: help with creating dict from string
On Thursday, November 6, 2014 12:41:10 PM UTC-5, Peter Otten wrote: > Tim wrote: > > > hi, I have strings coming in with this format: > > > > '[one=two, three=four five, six, seven=eight]' > > > > and I want to create from that string, this dictionary: > > {'one':'two', 'three':'four five', 'six':True, 'seven':'eight'} > > > > snip > > Not everything has to be a one-liner ;) If it works I don't think something > > >>> s = '[one=two, three=four five, six, seven=eight]' > >>> def fix(pair): > ... key, eq, value = pair.partition("=") > ... return key.strip(), value if eq else True > ... > >>> dict(fix(t) for t in s.strip("[]").split(",")) > {'three': 'four five', 'seven': 'eight', 'one': 'two', 'six': True} > > is particularly inelegant. Are you sure that your grammar is not more > complex than your example, e. g. that "," cannot occur in the values? hi Peter, I definitely wouldn't say that is inelegant :-) I had never used the partition method and I didn't realize (or maybe remember) that strip could take a string of characters, not just one. Oh yes, I am positive about the grammar--no commas are allowed in the values. I think your solution is pretty elegant. Thanks for your help! --Tim -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
On Tuesday, November 4, 2014 11:12:31 AM UTC-8, Ethan Furman wrote: > If you really absolutely positively have to have the signature be correct for > each instance, you may to either look at a > function creating factory, a class creating factory, or a meta-class. +1. Overriding __call__() within the class definition, over and over again, with different function, looks awkward to me. -- https://mail.python.org/mailman/listinfo/python-list
Re: help with creating dict from string
On Thursday, November 6, 2014 12:41:10 PM UTC-5, Peter Otten wrote: > Tim wrote: > > > hi, I have strings coming in with this format: > > > > '[one=two, three=four five, six, seven=eight]' > > > > and I want to create from that string, this dictionary: > > {'one':'two', 'three':'four five', 'six':True, 'seven':'eight'} > > > > snip > > Not everything has to be a one-liner ;) If it works I don't think something > > >>> s = '[one=two, three=four five, six, seven=eight]' > >>> def fix(pair): > ... key, eq, value = pair.partition("=") > ... return key.strip(), value if eq else True > ... > >>> dict(fix(t) for t in s.strip("[]").split(",")) > {'three': 'four five', 'seven': 'eight', 'one': 'two', 'six': True} > > is particularly inelegant. Are you sure that your grammar is not more > complex than your example, e. g. that "," cannot occur in the values? hi Peter, I definitely wouldn't say that is inelegant :-) I had never used the partition method and I didn't realize (or maybe remember) that strip could take a string of characters, not just one. Oh yes, I am positive about the grammar--no commas are allowed in the values. I think your solution is pretty elegant. Thanks for your help! --Tim -- This is a very clever solution. I just came across the need for something similar. Good question, excellent solution. Thank you!-- https://mail.python.org/mailman/listinfo/python-list
Re: I need algorithm for my task
Probably homework, you are a good man ! -- https://mail.python.org/mailman/listinfo/python-list
Re: Python has arrived!
Grant Edwards wrote: > According to > http://www.theregister.co.uk/2014/11/06/hackers_use_gmail_drafts_as_dead_drops_to_control_malware_bots: > > "Attacks occur in two phases. Hackers first infect a targeted >machine via simple malware that installs Python onto the device, >[...]" > A virus that runs on Python. It had to happen sooner or later. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
Roberto Martínez wrote: > Yikes, I didn't realize the difference in inheritance. > > The thing with this is tricky. I need the change in the instance, not in > the class, because I have multiple instances and all of them must have > different implementations of __call__. > > The workaround of calling a different method inside __call__ is not valid > for my case because I want to change the *signature* of the function also > -for introspection reasons. This is somewhat of a code smell. It's a bit whiffy, which doesn't *necessarily* mean it is off, only that it could be. You should think hard about your use-case and consider alternative strategies. Like, the strategy design pattern :-) The real problem here is that the individual functions have different signatures. If they had the same signature, then you could bake that into the __call__ method and simply call a per-instance method: class X: # Variation on the strategy design pattern. def __call__(self, spam, eggs=12): method = getattr(self, 'my_custom_method', None) if method is None: # Default behaviour. ... else: return method(self, spam, eggs) Then simply add a `my_custom_method` function to the individual instances. The different functions would provide different algorithms (implementations) for the same task, with the same interface. This is exactly the problem with the Strategy design pattern is supposed to solve. But the smelly part here is that your custom functions take different signatures, which suggests that they aren't providing different algorithms for the same task. Different signatures means that they are *not* interchangeable, that they have different calling conventions and presumably do different things: # This only works in Python 2 with "classic (old-style) classes" a, b, c = [X() for i in range(3)] a.__call__ = lambda self: self.spam + 1 b.__call__ = lambda self, x, y: (self.eggs or x)*y c.__call__ = lambda self, value: setattr(self, "spam", value) That's a strong violation of the expectation that any two instances of the same class should be more or less interchangeable, with at most a few exceptional cases (e.g. you can't swap the int instance 0 for the instance 2 in the expression x/2). But it's not *always* wrong, functions themselves are all instances of FunctionType, and every instance does something different when called. E.g. while you could swap math.sin for math.cos, since both take the same parameters, you cannot swap math.sin for len. Nevertheless, I urge you strongly to think hard about what problem you are really trying to solve. "Dynamically override __call__" is just a means to an end. Perhaps there is something less magically you can do to solve the problem? Is there some way to ensure that all the instances have the same interface? This might be easy, given that they can store per-instance state. If instance "a" needs an extra parameter that other instances don't, perhaps it can take it from an instance attribute instead of an argument. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Python has arrived!
On Nov 6, 2014 10:47 PM, "Sturla Molden" wrote: > > Grant Edwards wrote: > > According to > > http://www.theregister.co.uk/2014/11/06/hackers_use_gmail_drafts_as_dead_drops_to_control_malware_bots : > > > > "Attacks occur in two phases. Hackers first infect a targeted > >machine via simple malware that installs Python onto the device, > >[...]" > > > > A virus that runs on Python. It had to happen sooner or later. It's not a Python virus. The infection vector can be anything. The interesting part is that they're using browser automation to open a real-time, encrypted, virtually undetectable and untraceable channel to the malware over a port (443) that is frequently used and very rarely blocked, via a host (gmail.com) that is also frequently used and rarely blocked (and there would likely be plenty of alternatives to choose from if it were), and without needing to create any sort of server on the target machine. The fact that Python is involved is incidental. -- https://mail.python.org/mailman/listinfo/python-list
Re: Real-world use of Counter
On Nov 6, 2014 10:51 AM, "Ian Kelly" wrote: > > On Nov 6, 2014 1:06 AM, "Rustom Mody" wrote: > > Calling a bag as counter is inappropriate for an analogous reason > > to why calling a dictionary as a 'hash' is inappropriate -- > > it confuses an implementation detail for fundamental semantics. > > I've never liked the term "bag". In addition to being nonstandard it's also very nonintuitive. "Multiset" is fine, except that it implies the collection is a type of set, which the Python Counter is not. I was thinking about this today, and it seems to me that the Python Counter is not really even a multiset. * The size of a multiset would be the count of all the elements; the len of a Counter is only the number of keys. * The multiplicity of an element in a multiset is restricted to the natural numbers; the count of an element in a Counter can be any integer, even negative. * In a Counter, a key with a count of 0 is a distinct state from a key not being present at all; in the latter case the element is not in the Counter, while in the former case it *is* in the Counter. These states are also distinct for the purpose of equality. -- https://mail.python.org/mailman/listinfo/python-list
Re: Understanding "help" command description syntax - explanation needed
Chris Angelico wrote: > On Wed, Nov 5, 2014 at 11:31 PM, Ivan Evstegneev > wrote: That's what I'm talking about (asking actually), where do you know it from? >> I know it because I've been a programmer for 39 years. >> >> I didn't intend to offence anyone here. Just asked a questions ^_^ > > Don't worry about offending people. Even if you do annoy one or two, > there'll be plenty of us who know to be patient :) And I don't think > Larry was actually offended; it's just that some questions don't > really have easy answers - imagine someone asking a great > mathematician "But how do you KNOW that 2 + 2 is 4? Where's it written > down?"... all he can say is "It is". An ordinary mathematician will say: "Hold up two fingers. Count them, and you get one, two. Now hold up another two fingers. Count them, and you will get two again. Hold them together, count the lot, and you get one, two, three, four. Therefore, 2+2 = 4." A good mathematician might start with the empty set, ∅ = {}. [Aside: if the symbol looks like a small box, try changing your font -- it is supposed to be a circle with a slash through it. Lucinda Typewriter has the glyph for '\N{EMPTY SET}'.] That empty set represents zero. Take the set of all empty sets, {∅} = {{}}, which represents one. Now we know how to count: after any number, represented by some set, the *next* number is represented by the simplest set containing the previous set. Having defined counting, the good mathematician can define addition, and go on to prove that 2+2 = 4. This is, essentially, a proof of Peano Arithmetic (PA), which one can take as effectively the basic arithmetic of counting fingers, sheep or sticks. But a *great* mathematician will say, "Hmmm, actually, we don't *know* that 2+2 equals 4, because we cannot prove that arithmetic is absolutely consistent. If arithmetic is not consistent, then we might simultaneously prove that 2+2 = 4 and 2+2 ≠ 4, which is unlikely but not inconceivable." Fields medallist Vladimir Voevodsky is a great mathematician, and he apparently believes that the consistency of Peano Arithmetic is still an open question. http://m-phi.blogspot.com.au/2011/05/voevodsky-consistency-of-pa-is-open.html Another way to look at this, not necessarily Voevodsky's approach, is to note that the existing proofs of PA's consistency are *relative* proofs of PA. E.g. they rely on the consistency of some other formal system, such as the Zermelo-Frankel axioms (ZF). If ZF is consistent, so is PA, but we don't know that ZF is consistent... -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Understanding "help" command description syntax - explanation needed
On Fri, Nov 7, 2014 at 4:47 PM, Steven D'Aprano wrote: > But a *great* mathematician will say, "Hmmm, actually, we don't *know* that > 2+2 equals 4, because we cannot prove that arithmetic is absolutely > consistent. If arithmetic is not consistent, then we might simultaneously > prove that 2+2 = 4 and 2+2 ≠ 4, which is unlikely but not inconceivable." > And the mother of a young child will say "It just is. Now eat your greens." ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Understanding "help" command description syntax - explanation needed
在 2014年11月5日星期三UTC+8下午8时17分11秒,larry@gmail.com写道: > On Wed, Nov 5, 2014 at 7:13 AM, Ivan Evstegneev > wrote: > > Firtst of all thanks for reply. > > > >>>brackets [] means that the argument is optional. > > > > That's what I'm talking about (asking actually), where do you know it from? > > I know it because I've been a programmer for 39 years. that's awesome!! -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
John Ladasky writes: > On Tuesday, November 4, 2014 11:12:31 AM UTC-8, Ethan Furman wrote: > >> If you really absolutely positively have to have the signature be correct >> for each instance, you may to either look at a >> function creating factory, a class creating factory, or a meta-class. > > +1. Overriding __call__() within the class definition, over and over again, > with different function, looks awkward to me. A possibility to get the original approach implemented looks like: make "__call__" a descriptor on the class which looks up the real method on the instance. -- https://mail.python.org/mailman/listinfo/python-list