Re: Question on lambdas
On 12/09/2014 02:15 AM, memilanuk wrote: On 12/08/2014 09:30 PM, Ben Finney wrote: memilanuk writes: ... lambda: update_label2('A', 100) would this work the same? (I don't know what you mean here by “the same”; the same as what?) The above creates a new function, which expects no parameters (because there are no parameters before its ‘:’). The function, when called, will return the value of the expression ‘update_label2('A', 100)’. It looks as though it'd be passing the same two parameters to the same function... Yes, it looks that way, and that's what it does. The parameters are fixed in the expression and will be the same each time the new function is called. lambda: 'A', 100: update_label2() This is a syntax error. Have you tried experimenting with these? Carefully read the reference material on the ‘lambda’ syntax, and create some functions and experiment with them. Fair enough. What I was trying to do when I got into all this was something like this: import tkinter as tk root = tk.Tk() root.wm_title('Radio Buttons') label1 = tk.Label(root) label1.config(text='Please select an option below.') label1.pack() def update_label2(option, value): selection = "current selection is: \n\n" + str(option) + ": " + str(value) label2.config(text=selection) var = tk.IntVar() var.set(100) R1 = tk.Radiobutton(root, text='A', value=100, variable=var, command=lambda: update_label2('A', 100)) R1.pack(anchor='center') R2 = tk.Radiobutton(root, text='B', value=80, variable=var, command=lambda option='B', value=80: update_label2()) R2.pack(anchor='center') R3 = tk.Radiobutton(root, text='C', value=60, variable=var, command=lambda: update_label2('C', 60)) R3.pack(anchor='center') label2 = tk.Label(root) label2.config(text='Current selection is: \n \nA: 100') label2.pack() root.mainloop() So to me, the purpose of 'lambda' in this case is to call a function when a particular widget - in this case a radio button - is clicked. Thats why I wondered if 'lambda: update_label2('A', 100)' - where I'm using lambda to call another function, with the parameters inside the parentheses, was equivalent to 'lambda 'A', 100: update_label2()' where I would be using lambda to 'feed' the parameters to the function. You can certainly use lambda to "feed" the values, but you're calling the update_label function with no arguments. If you always want to pass those particular values, stick to the command=lambda: update_label2('A', 100)) version. If the values have to be calculated, then you might want command=lambda: update_label2('A', 100*SOME_GLOBAL)) But specifying arguments to the lambda that you don't use makes no sense. command=lambda option='B', value=80: update_label2()) The locals option and value aren't being used, so they're just wasted characters. In another context, something like: command=lambda option='B', value=80: update_label2(option, 2*value)) might make sense, but since tkinter isn't going to pass any arguments to the function, there's no point in declaring them. Try writing ordinary functions for your command= to use, and experiment with those. def mycallback(): update_label2('A', 100) command = mycallback Notice that tkinter will not be passing any arguments, so there's no point in having any parameters in mycallback(). But also notice that if you do declare such parameters (with default values), those values won't be automatically passed to the update_label() function. In other words, this: def mycallback(a = 5, b = 12): update_label2() doesn't automagically pass a and b into update_label2. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
Rustom Mody wrote: > On Friday, December 5, 2014 4:13:27 PM UTC+5:30, Steven D'Aprano wrote: >> But most of all, I despise the menus that pop up covering what I am >> trying to read the page just because I happened to move the mouse over a >> button. I loathe the practice of stuffing content into menus instead of >> using links to individual web pages. And I hold nothing but scorn for the >> fact that the main page has a slideshow. > > I thought I'd argue against this (and the general tenor of these > complaints) Tried to click on the > in what looked like a console session > > and for the last 5 minutes I am staring at > Loading console ... > > with the L in a different color... > > Pretty... but not exactly what I expect in an interactive console. > > Lest it seem like I am agreeing with these complaints, I'd like to say: > Either python goes this way or the way of Fortran and Cobol. You mean if Cobol had a shiny but disfunctional website we'd be using that instead of Python? That python.org is fear-driven design? OK, let's make an appearance on Myspace then... -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
On Tuesday, December 9, 2014 2:37:59 PM UTC+5:30, Peter Otten wrote: > Rustom Mody wrote: > > > On Friday, December 5, 2014 4:13:27 PM UTC+5:30, Steven D'Aprano wrote: > >> But most of all, I despise the menus that pop up covering what I am > >> trying to read the page just because I happened to move the mouse over a > >> button. I loathe the practice of stuffing content into menus instead of > >> using links to individual web pages. And I hold nothing but scorn for the > >> fact that the main page has a slideshow. > > > > I thought I'd argue against this (and the general tenor of these > > complaints) Tried to click on the > in what looked like a console session > > > > and for the last 5 minutes I am staring at > > Loading console ... > > > > with the L in a different color... > > > > Pretty... but not exactly what I expect in an interactive console. > > > > Lest it seem like I am agreeing with these complaints, I'd like to say: > > Either python goes this way or the way of Fortran and Cobol. > > You mean if Cobol had a shiny but disfunctional website we'd be using that > instead of Python? That python.org is fear-driven design? Among other things I mean... 1. 'Dysfunctional' can mean one of a. Intrinsically terrible idea b. Teething troubles c. Some linear combination of the above d. More likely non-linear 2. In our field, success correlates poorly with technical excellence. For examples you may consider a. A certain large Redmond company b. JS vs python on (???) metric [This must be somebody-or-others' law -- dunno who. Sturgeon's law is the closest I can get] 3. The rheostat can slide on many points between fear-driven and passion/innovation-driven design. > > OK, let's make an appearance on Myspace then... Heh! [Also see 3 above] -- https://mail.python.org/mailman/listinfo/python-list
IronPython 2.7.5 Released
On behalf of the IronPython team, I'm very happy to announce the release of IronPython 2.7.5[1]. Like all IronPython 2.7-series releases, .NET 4 is required to install it. Installing this release will replace any existing IronPython 2.7-series installation. Assemblies for embedding are provided for .NET 3.5, .NET 4, .NET 4.5, and Silverlight 5. IronPython 2.7.5 is primarily a collection of bug fixes[2] which smooths off many of the remaining rough edges. The complete list of changes[3] is also available. A major new feature is the inclusion of `ensurepip`, which will install the `pip` package manager: ``` ; -X:Frames is required when using pip ipy.exe -X:Frames -m ensurepip ; Run from an Administrator console if using IronPython installer ipy.exe -X:Frames -m pip install html5lib ``` **Note:** The assembly version of IronPython has changed to 2.7.5.0. All previous 2.7 versions had the same version (2.7.0.40) which caused issues when different versions were installed. Publisher policy files are used to so that applications don't have to be recompiled, but recompiling is strongly recommended. A huge thanks goes out to Pawel Jasinski, who contributed most of the changes in this release. Thanks is also due to Simon Opelt, Alex Earl, Jeffrey Bester, yngipy hernan, Alexander Köplinger,Vincent Ducros, and fdanny. For Visual Studio integration, check out Python Tools for Visual Studio[4] which has support for IronPython as well as CPython, and many other fantastic features. IronPython 2.7.5 is also available for embedding via NuGet. The main package is IronPython, and the standard library is in IronPython.StdLib. - Jeff [1] http://ironpython.codeplex.com/releases/view/169382 [2] http://bit.ly/ipy275fixed [3] https://github.com/IronLanguages/main/compare/ipy-2.7.4...ipy-2.7.5 [4] http://pytools.codeplex.com/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Question on lambdas
Am 09.12.2014 04:09 schrieb memilanuk: so in the first example in my original post: ... lambda: update_label2('A', 100) would this work the same? It looks as though it'd be passing the same two parameters to the same function... lambda: 'A', 100: update_label2() No. Even if it would be allowed by syntax, how should 'A', 100 be passed to update_label2() if it is not written inside its ()s? Also, in my second example: class MyText(Text): def __init__(self, master, **kw): apply(Text.__init__, (self, master), kw) self.bind("", lambda e: "break") I'm kind of missing what 'e' is and where its defined and what it's supposed to be passing to "break"...? Passing to "break"? A string cannot be passed anything. What bind() expects is any callable which takes an event object (IIRC). As you don't need any information from the event object here, you can ignore it (but it must be oresent, otherwise the call would fail). What the function does is just return "break". What sense this should have is unclear to me; probably the return value is just ignored. I was reading in 'Programming Python 4th ed' by Lutz and he talks about something to do with default values vs. enclosing scopes... that something like: lambda x=x: some_expr when evaluated inside a function loop to create buttons, etc., causes 'x' to be evaluated as the default value at the function creation time, vs. when the function is actually called. Do I have that more or less correct? Yes. This one takes the current value of x inside the function. Compare these: x = 4 f1 = lambda: x x = 5 f2 = lambda: x x = 42 print f1(), f2() What could one expect? "4 5", maybe. What does one get? "42 42". Why? Because the x is evaluated at the time it is indeed called. We can work around this with x = 4 f1 = lambda y=x: y x = 5 f2 = lambda y=x: y x = 42 print f1(), f2() (you can take x for y here, but this one is better understandable) Here each of the function gets the respective value "tattooed in"; we get "4 5" indeed as output. Downside is that we have the possibility to do print f1(123) which indeed gives 123. If we want to disallow this kind of calls, we could do def create_const_function(val): def inner_function(): return val or just create_const_function = lambda val: lambda: val and then f1 = create_const_function(4) f2 = create_const_function(5) print f1(), f2() et voilà. Thomas -- https://mail.python.org/mailman/listinfo/python-list
serial data and web
I would like to get data from serial port and send it to a web page. I think that getting data from serial port shopuld not be difficult in python. I've found some interesting links about it. How can I send after the datas directly to a web page? -- https://mail.python.org/mailman/listinfo/python-list
Re: serial data and web
On 12/09/2014 02:39 PM, manduk wrote: I would like to get data from serial port and send it to a web page. I think that getting data from serial port shopuld not be difficult in python. I've found some interesting links about it. How can I send after the datas directly to a web page? "A web page"? Did you mean a Web server? Basically, you'll have to upload your data to a Web Server, then the server will serve your data. Depending on how your server is setup, you'll have to use FTP, RSync, HTTP GET or POST or PUT,... There is plenty of ways to upload some content. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question on lambdas
Ben Finney wrote: > Christoph Becker writes: > >> Ben Finney wrote: >> >>> It's best to remember that ‘lambda’ is syntactic sugar for creating >>> a function; the things it creates are not special in any way, they >>> are normal functions, not “lambdas”. >> >> Could you please elaborate why ‘lambda’ does not create “lambdas”. I'm >> a Python beginner (not new to programming, though), and rather >> confused about your statement. > > We already have a term for what the ‘lambda’ keyword creates: a > function. > > That is, ‘lambda’ creates a function object, without anything to > distinguish it from a function created any other way. Ah, now I understand. It's "just" about proper naming. Thanks. :) -- Christoph M. Becker -- https://mail.python.org/mailman/listinfo/python-list
Re: encrypt the http request url on the local machine
在 2014年12月9日星期二UTC+8下午2时58分36秒,iMath写道: > my software on the local machine needs to send http request to a specific web > server , is there any way to protect the http request url from being found by > Packet analyzer software like Wireshark and fiddler. The sever is not mine, > so I can do nothing in the server . > > It would be better to show some code, I am an absolutely newbie in encryption > . I don't know any form of encryption that the server _does_ support, the sever is not mine. Here I just don't want to any other guys using packet analyzer software know which server my software is sending data to -- https://mail.python.org/mailman/listinfo/python-list
Re: serial data and web
"A web page"? Did you mean a Web server? ok I mean I would like to view the datas on a web page Basically, you'll have to upload your data to a Web Server, then the server will serve your data. Depending on how your server is setup, you'll have to use FTP, RSync, HTTP GET or POST or PUT,... There is plenty of ways to upload some content. not only upload in a folder of a webserver...I wish to see in real time the datas in a public html page. I get the data from serial port and then I put them in a remote page. Which is the best way to transfer datas from a text file for example and send it on web? -- https://mail.python.org/mailman/listinfo/python-list
Re: serial data and web
- Original Message - > From: "manduk" > > "A web page"? > > Did you mean a Web server? > not only upload in a folder of a webserver...I wish to see in real > time > the datas in a public html page. > I get the data from serial port and then I put them in a remote page. > Which is the best way to transfer datas from a text file for example > and > send it on web? One simple solution : Use flask http://flask.pocoo.org/ You'll be able to create a web app very quickly. Accessing a serial port from that app and update the html will be easy. For this solution to work, the machine accessing the serial port and the machine serving the html pages is the same. If you need your html pages to be served by another machine, you can implement the html POST/GET requests (see the flask doc). JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tuple of lists concatenation - function vs comprehension
On Monday, December 8, 2014 3:52:53 AM UTC+5:30, Terry Reedy wrote: > On 12/7/2014 10:28 AM, Ivan Evstegneev wrote: > > Hi Shiyao, > > > > Now I see, that it was kind of dumb question... > > > > x = ([1, 2], [3, 4], [5, 6]) > > L = [] > [L.extend(i) for i in x] > > [None, None, None] > > Using a list comprehension for the expression side-effect, when you do > not actually want the list produced by the comprehension, is considered > bad style by many. There is nothing wrong with explicit loops. Yes loops are ok If you want a solution along the lines you (OP) are seeking here is one: >>> from operator import add >>> reduce(add, [[1,2],[3,4]], []) [1, 2, 3, 4] >>> Notes 1. Terry's suggestion to use (the obvious) loop should be heeded 2. Which will also be more efficient 3. The reason I mention the reduce is that its a part of FP lore: Every map (and therefore comprehension) can be put into the form of a reduce. But not the contrary. -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
Rustom Mody writes: > Pretty... but not exactly what I expect in an interactive console. I have to agree although the console works for me. But shame on the site maintainers though, the interactive console comes up with Python 3.3.6 instead of current 3.4.2 (and IPython 2.10, also not the latest). -- https://mail.python.org/mailman/listinfo/python-list
Re: encrypt the http request url on the local machine
On 12/09/2014 07:43 AM, iMath wrote: 在 2014年12月9日星期二UTC+8下午2时58分36秒,iMath写道: my software on the local machine needs to send http request to a specific web server , is there any way to protect the http request url from being found by Packet analyzer software like Wireshark and fiddler. The sever is not mine, so I can do nothing in the server . It would be better to show some code, I am an absolutely newbie in encryption . I don't know any form of encryption that the server _does_ support, the sever is not mine. Here I just don't want to any other guys using packet analyzer software know which server my software is sending data to There's a lot you're leaving out about the network topology. The answers to avoiding/confusing someone else's packet sniffer are either: 1) change the content so they can see where it's going, but have no idea why 3) use a route that doesn't go past their sniffing software 2) change the data traffic so they don't recognize where it's going Encryption solves the 1st. The problem is that the other end has to know the encryption scheme you're using, and cooperate in using it. From what you're saying, that can't happen. The best way to solve the 2nd is to move your laptop to some place your sniffers don't have visibility to. And make sure the route from your laptop to the server does not go near the sniffers. Maybe you could talk the receptionist of the building where the server is into letting you plug in there. Or you could use a library or other public wifi, where you hope they're not nearby (in a network topology sense). The third approach involves something like a proxy. You send encrypted data to the proxy, which then decrypts it and resends it to the server. The server responds to the proxy, which encrypts the response and sends it to you. There are many things similar to this, used by crackers all over the world, as well as for some legitimate purposes. One legitimate proxy-like thing many of us have used is an ip-tunnel like a VPN. I have telecommuted to jobs where my access into the corporate network is via VPN, and all a sniffer at my house would see is access to a single machine, not to the final machine within the company network. It probably would be best if you explained the actual scenario. Are you trying to get to black-listed sites from within a corporate environment, and afraid the company IT department will detect it and get you fired? Best answer is to do it at home instead, where they're unlikely to have access. If you wind up needing a proxy, you have to open an account with them, and make the arrangements. I've enabled a proxy for my machine when it was necessary, but have no idea how to program it; it also may vary depending on the proxy server. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: encrypt the http request url on the local machine
On Wed, Dec 10, 2014 at 2:31 AM, Dave Angel wrote: > If you wind up needing a proxy, you have to open an account with them, and > make the arrangements. I've enabled a proxy for my machine when it was > necessary, but have no idea how to program it; it also may vary depending > on the proxy server. I know how to program one, and it's not difficult. However, I'm sitting tight on this one until I hear some legit justification for this, especially given that the traffic from the proxy to the destination server won't be encrypted. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
>> Lest it seem like I am agreeing with these complaints, I'd like to say: >> Either python goes this way or the way of Fortran and Cobol. > > You mean if Cobol had a shiny but disfunctional website we'd be using that > instead of Python? Why would he mean that? If !A implies !B, it does *not* follow that A implies B. Here A = "shiny website" and B = "success". Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- https://mail.python.org/mailman/listinfo/python-list
Re: module import questions and question about pytest and module import
To: sam pendleton On 12/07/2014 11:50 AM, sam pendleton wrote: > Thanks for getting back with me! > > On Sun, Dec 7, 2014 at 11:26 AM, Dave Angel wrote: >> On 12/05/2014 11:50 PM, sam pendleton wrote: >>> >>> garage/ >>> |- __init__.py >>> |- cars/ >>> |- __init__.py >>> |- hummer.py >>> tests/ >>> |- test_cars.py >>> >>> at the top of test_cars.py, there is this: >>> from garage.cars import hummer >>> >>> pytest is on this import statement, so i guess it's incorrect. >> >> >> No idea what that statement is trying to say. > > Sorry Dave, I was saying that pytest is hung up there stating it can't > import that module. Why don't you just try running the module, and post the stacktrace when it gets an exception? I've never used pytest, and don't know why it would hang on any particular line. > > >> If you're going to import something, it either has to be on the sys.path, or >> in the current directory. Is garage/ on your sys.path? >> >> You can examine sys.path by >> import sys >> print(sys.path) > > Having to put the garage package on the sys.path seems a little off, > why wouldn't relative imports work? > > Do most people somehow put their packages in sys.path when bundling > their python packages up to be shared with setuptools or other python > package managers? If so, how? > When you get to the point of bulding a distribution, you'll be putting your packages in the dist_packages directory, which is on sys.path. However, generally your distribution utility will handle those details. In the meantime, you can set some environment variable to add locally to your sys.path. As for relative import versus other choices, that varies between Python 2.x and 3.x, and you haven't specified exactly what Python version you're running or what OS you're on. In Python 2.x, relative import was considered to be ambiguous, and people figured it had to change. You might want to read https://docs.python.org/2.5/whatsnew/pep-328.html -- -- DaveA --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk =?
> with open(localpath, 'wb') as fl: > PermissionError: [Errno 13] Permission denied: 'c:' I remember gloomily (haven't used windows since ages) that newer Windows versions don't like users to write directly to C:. Have you tried to save the file to your Documents folder? Regards, Alba --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
To: Luuk On Mon, 08 Dec 2014 19:11:40 +0100, Luuk wrote: > On 8-12-2014 18:37, ishish wrote: >>> with open(localpath, 'wb') as fl: >>> PermissionError: [Errno 13] Permission denied: 'c:' >> >> I remember gloomily (haven't used windows since ages) that newer >> Windows versions don't like users to write directly to C:. Have you >> tried to save the file to your Documents folder? >> >> Regards, >> Alba > > no, it's the ssh-server denying a log on from 'root' windows systems dont usualy have an SSH server & root is not a normal windows user name on most systems that DO have a ssh server root logins are usually prohibited, either enable root logins (dangerous) or log in with a user that has permissions to do what you require. if you don't have access to the server then you need assistance from someone who is authorised. -- Do you know Montana? --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: Nested dictionaries from a list ?
To: Denis McMahon On 12/07/2014 06:52 PM, Denis McMahon wrote: > On Sun, 07 Dec 2014 12:01:26 -0500, Dave Angel wrote: > >> On 12/07/2014 11:18 AM, Wacky wrote: > >>> I've a list of users > >> I haven't run this through the Python, so please forgive any typos. > >> users = [ >> mess = { > > users is redundant, as it's mess.keys() > > maintaining a separate list of users and having the users as the keys in > mess suggests redundancy, and the potential for errors if the two data > items get out of synch. Better imo to just have the data in one place. > Unless there's an order that wants to be retained. But I would change the list into a list of user objects, rather than of strings. And I'd know that eventually it would be a sparse list (as users come and go, and you don't want to reuse the indices). So it would be another dictionary mapping userid and User instance. -- DaveA --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
why can't download file from linux server into local window disk c:?
My vps ip is x.y.z.w ,i want to download /etc/passwd from linux server into my local window disk c: . import paramiko host = "x.y.z.w" port = 22 transport = paramiko.Transport((host, port)) password = "mykey" username = "root" transport.connect(username = username, password = password) sftp = paramiko.SFTPClient.from_transport(transport) filepath = '/etc/passwd' localpath = 'c:' sftp.get(filepath, localpath) Traceback (most recent call last): File "", line 1, in File "D:\Python34\lib\site-packages\paramiko\sftp_client.py", line 719, in get with open(localpath, 'wb') as fl: PermissionError: [Errno 13] Permission denied: 'c:' --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
To: alister Copy: python-list@python.org On 2014-12-08 18:46, alister wrote: > on most systems that DO have a ssh server root logins are usually > prohibited, either enable root logins (dangerous) or log in with a > user that has permissions to do what you require. if you don't have > access to the server then you need assistance from someone who is > authorised. Just for the record, you can enable root logins but disallow password logins, so root has to be done with a public/private key-pair. That said, I do as you describe and still SSH to my ssh-user account, then "su" to root as needed from there. But at least there's a middle ground that isn't as vulnerable as putting a root account out there to be banged on by any script-o-matic bot that finds it. I also like to change my external SSH port to something non-traditional (and have configured port-knocking in the past) to prevent the obvious pokes I would otherwise see in my sshd/auth/access logs. -tkc --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] how to make program suggest to install missing modules
To: Jean-Michel Pichavant On Monday, December 8, 2014 10:46:47 AM UTC-8, Jean-Michel Pichavant wrote: > - Original Message - > > From: sohcahto...@gmail.com > > try: > > import someModule > > except ImportError: > > print "Module is missing" > > # handle it! > > > > Just make sure to attempt to import it again after making the call to > > pip to install it. > > Note that ImportError may be raised for other reasons than a missing module. > > Check https://docs.python.org/2/library/imp.html and the imp.find_module, it could be a safer way to check for a missing module. > > JM > > > -- IMPORTANT NOTICE: > > The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. Good point. Of course, imp.find_module ALSO throws ImportError if the module can't be found, but at least in that case, you'd know the exact cause. --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
To: Tim Chase Copy: python-list@python.org (python-list@python.org) On Tue, Dec 9, 2014 at 6:50 AM, Tim Chase wrote: > Just for the record, you can enable root logins but disallow password > logins, so root has to be done with a public/private key-pair. > > That said, I do as you describe and still SSH to my ssh-user account, > then "su" to root as needed from there. But at least there's a > middle ground that isn't as vulnerable as putting a root account out > there to be banged on by any script-o-matic bot that finds it. I've done both of these. Most of my boxes don't have passwords on the root account AND don't allow SSH to root, relying on a sudo-enabled account usually; and it's perfectly possible to also deny password access to *any* account via SSH. Quite good for security... though it can create an awkward bootstrap problem if you lose all private keys that had access. ChrisA --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
To: ishish On 8-12-2014 18:37, ishish wrote: >> with open(localpath, 'wb') as fl: >> PermissionError: [Errno 13] Permission denied: 'c:' > > I remember gloomily (haven't used windows since ages) that newer Windows > versions don't like users to write directly to C:. Have you tried to > save the file to your Documents folder? > > Regards, > Alba no, it's the ssh-server denying a log on from 'root' --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: Maintaining Maximum Line Length When Using Tabs Instead of Spaces?
To: sohcahto...@gmail.com sohcahto...@gmail.com writes: > My terminals are 120 columns wide. Mine are wider. So what? > Are there still people that are limiting their terminals to 80 > columns? I don't know. Terminal width is not the sole reason to keep code lines within 80 columns. -- \ ΓÇ£The fundamental principle of science, the definition almost, | `\ is this: the sole test of the validity of any idea is | _o__) experiment.ΓÇ¥ ΓÇöRichard P. Feynman | Ben Finney --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
To: pengsir On 9-12-2014 09:14, pengsir wrote: > > > My vps ip is x.y.z.w ,i want to download /etc/passwd from linux server > into my local window disk c: . > > import paramiko > host = "x.y.z.w" > port = 22 > transport = paramiko.Transport((host, port)) > password = "mykey" > username = "root" > transport.connect(username = username, password = password) > sftp = paramiko.SFTPClient.from_transport(transport) > filepath = '/etc/passwd' > localpath = 'c:' > sftp.get(filepath, localpath) > > Traceback (most recent call last): >File "", line 1, in >File "D:\Python34\lib\site-packages\paramiko\sftp_client.py", line > 719, in get > > with open(localpath, 'wb') as fl: > PermissionError: [Errno 13] Permission denied: 'c:' You, 'root', does not have enoug permission to do it C:\temp>\util\Putty\pscp root@opensuse:/etc/passwd . Using keyboard-interactive authentication. Password: Access denied --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
When do default parameters get their values set?
I ran into an issue setting variables from a GUI module that imports a back end module. My approach was wrong obviously but what is the best way to set values in a back end module. #module name beTest.py cfg = { 'def' : 'blue'} def printDef(argT = cfg['def']): print argT #module name feTest import beTest beTest.cfg['def'] = "no red" beTest.printDef() This prints blue. I suppose because I am changing a local copy of cfg dictionary. What is the write approach here? Thanks Bill --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
To: Luuk Copy: python-list@python.org (python-list@python.org) On Tue, Dec 9, 2014 at 5:11 AM, Luuk wrote: > On 8-12-2014 18:37, ishish wrote: >>> >>> with open(localpath, 'wb') as fl: >>> PermissionError: [Errno 13] Permission denied: 'c:' >> >> >> I remember gloomily (haven't used windows since ages) that newer Windows >> versions don't like users to write directly to C:. Have you tried to >> save the file to your Documents folder? >> >> Regards, >> Alba > > > no, it's the ssh-server denying a log on from 'root' It looks to me more like an issue with path naming. Try 'c:/' instead of 'c:', or use '/' to mean the root directory of the current drive. Alternatively, do a web search for the problem and the symptoms, as you're unlikely to be the first person to have run into this. ChrisA --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
[newbie] how to make program suggest to install missing modules
I'd like to add the following to a python-program: when a module (take rtlsdr as an example) is not installed on the system I'd like to ask the program something like: module rtlsdr is missing, shall I install it? y or n if n -->sorry but then I can't run this program and quit program if y -->execute this command: os.system(sudo pip install pyrtlsdr) continue program can anyone here show me how to perform this properly? thanks in advance hugo --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: When do default parameters get their values set?
To: bSneddon On 12/08/2014 05:10 PM, bSneddon wrote: > I ran into an issue setting variables from a GUI module that imports a back end module. My approach was wrong obviously but what is the best way to set values in a back end module. > To answer the subject line, the default parameter(s) are evaluated when the function is compiled, and then stored with the function. So in this case the default for argT is an immutable string "blue" Being immutable, nothing will change that for the run of the program. > #module name beTest.py > > cfg = { 'def' : 'blue'} > > def printDef(argT = cfg['def']): > print argT > > > #module name feTest > import beTest > > beTest.cfg['def'] = "no red" > beTest.printDef() > > > > This prints blue. I suppose because I am changing a local copy of cfg dictionary. What is the write approach here? > You're not making a local copy of any dictionary. The symptoms you have would be identical even if you run beTest.py directly (with those two lines added, of course). The RIGHT approach depends on what your goal is here. Obviously this is simplified from some more complex use, but you haven't stated what your desires are, so I don't necessarily know how to achieve them. There is only one dictionary, and it does change when you you say: beTest.cfg['def'] = "no red" But if you need to do a lookup in that dictionary upon calling primtDef(), then you're going to make the evaluation at that time, not at default-time. How about the following, fairly common idiom for default values: def printDef(argT = None]): if argT = None: argT = cfg['def'] print argT -- DaveA --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] how to make program suggest to install missing modules
To: hugocoolens On Monday, December 8, 2014 9:44:50 AM UTC-8, hugocoolens wrote: > I'd like to add the following to a python-program: > > when a module (take rtlsdr as an example) is not installed on the system I'd like to ask the program something like: > > module rtlsdr is missing, shall I install it? y or n > if n -->sorry but then I can't run this program and quit program > if y -->execute this command: > os.system(sudo pip install pyrtlsdr) > > continue program > > can anyone here show me how to perform this properly? > > thanks in advance > hugo Hint: try: import someModule except ImportError: print "Module is missing" # handle it! Just make sure to attempt to import it again after making the call to pip to install it. --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Is cmd.Cmd.cmdloop() integration with asyncio server possible?
I'm working on an asyncio server project. I'd also like to have a cmd.Cmd style command loop interface for spawning instances of the server. As far as I've seen, running an asyncio server requires ... loop.run_forever() ... And cmd.Cmd.cmdloop() is a blocking loop, so I'm not able to call them sequentially. Is there a way to get the cmdloop to run asynchronously? Or a way to call asyncio.streams.start_server from the cmdloop and actually have it run continuously? I've tried a few things but nothing has been successful. I should mention that by itself, the server functions. For brevity, I'll try to keep the code to what is relevant. class MyServer: ... def start(): server = asyncio.async( asyncio.streams.start_server( self.accept_client, host=self.ip, port=self.port, loop=self.loop ) ) return server ... class MyMenu(cmd.Cmd): def __init__(self, loop): cmd.Cmd.__init__(self) ... do_serve(self, **kwargs): server = MyServer(self.loop, **kwargs) instance = server.start() if __name__ == '__main__': loop = asyncio.get_event_loop() menu = MyMenu(loop) menu.cmdloop() Calling loop.run_forever() at any point breaks the menu functionality. Any help would be greatly appreciated. --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: Maintaining Maximum Line Length When Using Tabs Instead of Spaces?
To: sohcahto...@gmail.com On 12/08/2014 03:20 PM, sohcahto...@gmail.com wrote: >> > > On Sunday, December 7, 2014 6:26:01 PM UTC-8, jtan wrote: >> One reason why you would want max length 79 is because of working with terminals. Maybe ssh to you server and check how many spaces are consumed by a tab? In my boxes, it is usually 1 tab = 8 spaces. So perhaps just use that setting in your editor? > > > My terminals are 120 columns wide. > > Are there still people that are limiting their terminals to 80 columns? If so, why? I frequently have more than just one terminal open on my xserver. I might have several terminals, or I might also have a browser or another application. And I rearrange the windows so the parts I'm interested in are showing whatever I'd like to simultaneously see. > I mean, I can understand if you're running on an ancient square monitor, > but I see no reason to limit your terminal to 80 columns if you're running any sort of window environment on monitor with a horizontal resolution greater than 1280. What's square got to do with anything? I have displays ranging from about 3 inches across to about 29. The size matters, not usually the pixel count (my cell phone has 1920 pixels across). > > "Because that's how we've always done it!" is a pretty reason to continue doing something. > No need to throw feces around. There are several reasons besides history. 1) physical screen size, divided by the number of simultaneous windows one wants horizontally visible. 2) vision acuity. When the print gets small enough, my elderly eyes can't read it reliably. 3) Human preference and ability. Notice that large books and newspapers use multiple columns, or pictures & ads to break up the page. A line beyond some length makes it hard to take it all in at once. 4) Other media. Sometimes we actually make listings on paper. If code is only going to be used by one person, then it may make sense for that person to make it as wide as the size he personally can handle, with his abilities and equipment and usage habits. But when there are multiple people, it sometimes makes sense to constrain code to the most stringent of their abilities. And one's abilities change over time, just as his equipment does. -- DaveA --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
To: pengsir On 2014-12-09 08:14, pengsir wrote: > > > My vps ip is x.y.z.w ,i want to download /etc/passwd from linux server > into my local window disk c: . > > import paramiko > host = "x.y.z.w" > port = 22 > transport = paramiko.Transport((host, port)) > password = "mykey" > username = "root" > transport.connect(username = username, password = password) > sftp = paramiko.SFTPClient.from_transport(transport) > filepath = '/etc/passwd' > localpath = 'c:' > sftp.get(filepath, localpath) > > Traceback (most recent call last): > File "", line 1, in > File "D:\Python34\lib\site-packages\paramiko\sftp_client.py", line > 719, in get > > with open(localpath, 'wb') as fl: > PermissionError: [Errno 13] Permission denied: 'c:' > It's trying to open the file 'c:', but that's not a file, it's a folder. Try, say, 'c:/passwd' instead. --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: jitpy - Library to embed PyPy into CPython
To: python-list On 7 December 2014 at 14:31, Albert-Jan Roskam wrote: > On Sun, Dec 7, 2014 11:06 AM CET Stefan Behnel wrote: >> >>I think this is trying to position PyPy more in the same corner as other >>JIT compilers for CPython, as opposed to keeping it a completely separate >>thing which suffers from being "not CPython". It's a huge dependency, but >>so are others. > > You mean like psyco? Well, if implementation differences between cpython and pypy are a problem, it might be useful. I've only come across a few unimportant ones. Bu then, I never reimplement __del__. > http://pypy.readthedocs.org/en/latest/cpython_differences.html Some libraries don't work on PyPy; SciPy for example. If you want to use SciPy but use PyPy where appropriate, this is a good bet. --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
Am 09.12.2014 09:14 schrieb pengsir: > My vps ip is x.y.z.w ,i want to download /etc/passwd from linux server > into my local window disk c: . > localpath = 'c:' [...] > with open(localpath, 'wb') as fl: > PermissionError: [Errno 13] Permission denied: 'c:' That's completely clear: you are not allowed to create a file named 'c:'. You should replace it with a full path name, such as localpath = 'c:\\passwd' or such. Thomas --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
Am 08.12.2014 19:11 schrieb Luuk: > no, it's the ssh-server denying a log on from 'root' You are repating yourself. How could possibly with open(localpath, 'wb') as fl: PermissionError: [Errno 13] Permission denied: 'c:' be a problem with the SSH server? --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
To: Luuk Copy: python-list@python.org On 2014-12-08 19:11, Luuk wrote: > On 8-12-2014 18:37, ishish wrote: > >> with open(localpath, 'wb') as fl: > >> PermissionError: [Errno 13] Permission denied: 'c:' > > > > I remember gloomily (haven't used windows since ages) that newer > > Windows versions don't like users to write directly to C:. Have > > you tried to save the file to your Documents folder? > > > > Regards, > > Alba > > no, it's the ssh-server denying a log on from 'root' I'm going to go out on a limb and say that's pretty clearly not the issue. The exception states that the problem is one of permissions on the C: PermissionError: [Errno 13] Permission denied: 'c:' which ishish clearly identified as a "Windows doesn't let you do that any more" issue. Additionally, I don't know off the top of my if the Paramiko libraries expect a file-name, or if they expect a directory into which the file gets put based on the server-side name. The best solution is to do as ishish proposed: write the file to some other appropriate (i.e., writable) location. A simple fix might be import os # ... localpath = os.path.expanduser('~') or localpath = os.path.join( os.path.expanduser('~'), 'passwd.txt', ) A stop-gap solution might be to just run the program in a writable directory: c:\> cd %TEMP% c:\...\TEMP> python myprog.py A far worse solution would be to run the script as Administrator on the Win32 box, which will grant permission to write in the root of C: -tkc --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: Maintaining Maximum Line Length When Using Tabs Instead of Spaces?
To: jtan > On Mon, Dec 8, 2014 at 10:15 AM, Aahan Krish wrote: > My understanding from talking to different people is that many do use > > tabs (instead of spaces) for indentation in their code. > > > > My question is to them (because I want to use tabs too) is: how do you > > maintain a line-length of 79 characters? > > > > E.g. scenario: The tab setting in your editor could be 2 or 4, and in > > other developer's browser it could be 8. The code will be longer than > > 79 chars in the latter's editor. > > > > I want to know if it's at all possible or if you use some simple and > > realistic (practical) hacks. > > > > *PS: Please avoid, "That's why you should use spaces," type of > > comments. I would like to avoid flame wars.* > > > > TY, > > Aahan On Sunday, December 7, 2014 6:26:01 PM UTC-8, jtan wrote: > One reason why you would want max length 79 is because of working with terminals.á Maybe ssh to you server and check how many spaces are consumed by a tab?á In my boxes, it is usually 1 tab = 8 spaces.á So perhaps just use that setting in your editor? My terminals are 120 columns wide. Are there still people that are limiting their terminals to 80 columns? If so, why? I mean, I can understand if you're running on an ancient square monitor, but I see no reason to limit your terminal to 80 columns if you're running any sort of window environment on monitor with a horizontal resolution greater than 1280. "Because that's how we've always done it!" is a pretty shitty reason to continue doing something. --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: jitpy - Library to embed PyPy into CPython
To: Albert-Jan Roskam On Saturday, December 6, 2014 3:30:56 PM UTC-5, Albert-Jan Roskam wrote: > > On Fri, Dec 5, 2014 8:54 PM CET Mark Lawrence wrote: > > >For those who haven't heard thought this might be of interest https://github.com/fijal/jitpy > > Interesting, but it is not clear to me when you would use jitpy instead of pypy. Too bad pypy alone was not included in the benchmarks (cython would have also been nice). There are plenty of situations. For example, I am building an app that requires access to modules that don't currently work under pypy. With this tool I could still take advantage of pypy JIT, but use CPython for other stuff. --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
SQLObject 1.7.0
To: Python Announce Mailing List To: python-list@python.org (Python Mailing List) Hello! I'm pleased to announce version 1.7.0, the first stable release of branch 1.7 of SQLObject. What's new in SQLObject === * Python 2.5 is no longer supported. The minimal supported version is Python 2.6. * DateTimeCol and TimeCol can read values with microseconds (created by SQLObject 2.0) but do not write microseconds back. * Upgrade ez_setup to 2.2. * Adapt duplicate error message strings for SQLite 3.8. * Allow unicode in .orderBy(u'-column'). * Fix a minor bug in MSSQLConnection: do not override callable server_version with a non-callable. Contributors for this release are Geoffrey Wossum, Neil Muller and Andrew Trusty. For a more complete list, please see the news: http://sqlobject.org/News.html What is SQLObject = SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject == Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: https://pypi.python.org/pypi/SQLObject/1.7.0 News and changes: http://sqlobject.org/News.html Oleg. -- Oleg Broytmanhttp://phdru.name/p...@phdru.name Programmers don't die, they just GOSUB without RETURN. --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:
To: pengsir On Tue, 09 Dec 2014 00:14:15 -0800, pengsir wrote: > localpath = 'c:' > sftp.get(filepath, localpath) > with open(localpath, 'wb') as fl: > PermissionError: [Errno 13] Permission denied: 'c:' It's trying to open "c:", which is a drive, as if it was a file. You have to specify the destination filename, not just the directory. Also, you probably shouldn't be trying to write to the root directory of the C drive. You should probably be using a directory beneath either %USERPROFILE% or %ALLUSERSPROFILE%. Writing to the root of the system drive tends to require Administrator privileges. Even if the current user is an administrator, the process must have elevated privilege (e.g. via "Run as Administrator" or an explicit privilege-elevation request from within the code). --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: When do default parameters get their values set?
To: bSneddon Copy: python-list@python.org (python-list@python.org) On Tue, Dec 9, 2014 at 9:10 AM, bSneddon wrote: > I ran into an issue setting variables from a GUI module that imports a back end module. My approach was wrong obviously but what is the best way to set values in a back end module. > > #module name beTest.py > > cfg = { 'def' : 'blue'} > > def printDef(argT = cfg['def']): > print argT They're set when you define the function, and become attributes of the function. If you want to lazily fetch the defaults, here's one common idiom: def printDef(argT=None): """Print the argT value, defaults to cfg['def']""" if argT is None: argT = cfg['def'] print(argT) This depends on None not being a meaningful argument value, of course. If you need to have any object at all able to be passed in, you'd need to create a dedicated sentinel object, or use *args and unpack yourself; but for a lot of cases, None works fine. ChrisA --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: When do default parameters get their values set?
To: bSneddon Copy: python-list@python.org On 2014-12-08 14:10, bSneddon wrote: > I ran into an issue setting variables from a GUI module that > imports a back end module. My approach was wrong obviously but > what is the best way to set values in a back end module. > > #module name beTest.py > > cfg = { 'def' : 'blue'} > > def printDef(argT = cfg['def']): At this point (after the "def" has completed defining the function), the expression is evaluated and assigned to the default argument. > beTest.cfg['def'] = "no red" > beTest.printDef() > > This prints blue. I suppose because I am changing a local copy > of cfg dictionary. What is the write approach here? Well, you can bind to a default dictionary rather than an entry in that dictionary: cfg = {'def': 'blue'} def printDef(config=cfg): ... access(config['def']) which will make the look-up happen at run-time rather than definition/bind-time. beTest.cfg['def'] = 'Red!' beTest.printDef() # should print "Red!" -tkc --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Re: encrypt the http request url on the local machine
On Mon, 8 Dec 2014 22:58:20 -0800 (PST), iMath wrote: > my software on the local machine needs to send http request to a > specific web server , is there any way to protect the http request url > from being found by Packet analyzer software like Wireshark and > fiddler. The sever is not mine, so I can do nothing in the server . This is what Tor (onion routing) is for. Vaguely speaking ('cause I don't know much about Tor), you encrypt your entire HTTP request and send it to a Tor node. It gets passed around among Tor nodes until an "exit node" decrypts it and sends it to the destination server. Be aware, though, that if the destination server doesn't do HTTPS, the conversation between it and the Tor exit node is readable by snoops. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Solution to a problem,write terminal output to file
Hi All, I am facing a problem in python coding that is I have a client server program(programs a re in c code and client and server are its executable) on Linux machine. To run client i do this ./strace -c client and to run server i type this ./strace -c server When i give ctrl+c to client i see some output on the terminal, i want that output in the file i mean i want to send the ctrl+c signal programmatic ally to client after a minute and write the output in the file. if i use subprocess.Popen to execute ./strace -c client and give ctrl+c signal i don''t see any output on the terminal but if i see os.system to execute ./strace -c client i see the output on terminal.Now i want to send the ctrl+c signal to os.system and write the terminal output into a file. Please help me to do that. Can you provide a pseudo script. I will be very thankfull to you. Regards -- https://mail.python.org/mailman/listinfo/python-list
Re: Solution to a problem,write terminal output to file
On Wed, Dec 10, 2014 at 4:11 AM, Robert Clove wrote: > I am facing a problem in python coding that is > > I have a client server program(programs a re in c code and client and server > are its executable) on Linux machine. > To run client i do this ./strace -c client and to run server i type this > ./strace -c server > > When i give ctrl+c to client i see some output on the terminal, i want that > output in the file i mean i want to send the ctrl+c signal programmatic ally > to client after a minute and write the output in the file. > > if i use subprocess.Popen to execute ./strace -c client and give ctrl+c > signal i don''t see any output on the terminal but if i see os.system to > execute ./strace -c client i see the output on terminal.Now i want to send > the ctrl+c signal to os.system and write the terminal output into a file. I'm not entirely sure what you're trying to do here, but strace produces its output on Standard Error (aka "stderr"). You can simply redirect that to a file. That's the normal strace program. You might be running something completely different, since you're running "./strace"; but I would suggest that it probably uses either stderr or stdout ("Standard Output"), and you could redirect either or both. Try this, at the terminal (no Python involved): ./strace -c client >client_out 2>client_err Then press Ctrl-C, and see which of the files has the output. Based on that, you could configure subprocess.Popen to send the appropriate stream to a file. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Iterables struggling using map() built-in
On 12/9/2014 12:03 AM, Terry Reedy wrote: Roy Smith wrote: Chris Angelico wrote: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res) Ugh. When I see "while foo", my brain says, "OK, you're about to see a loop which is controlled by the value of foo being changed inside the loop". What is nasty to me is that to understand the loop, one must do a whole program analysis to determine both that 'iters' is not rebound and that the list it is bound to is not mutated. To do the later, one must not only read the loop body, but also preceding code to make sure the list is not aliased. > iters is empty if and only if args is empty. If args is empty, iters should not be created. if args: iters = ... while True ... (return on exception) makes the logic clear. Once the logic is clear and 'localized', even a simple compiler like CPython's can see that this is a loop-forever construct and that the loop test is unnecessary. So it can be removed. >>> dis("while a: b+=1") 1 0 SETUP_LOOP 20 (to 23) >>3 LOAD_NAME0 (a) 6 POP_JUMP_IF_FALSE 22 9 LOAD_NAME1 (b) 12 LOAD_CONST 0 (1) 15 INPLACE_ADD 16 STORE_NAME 1 (b) 19 JUMP_ABSOLUTE3 >> 22 POP_BLOCK >> 23 LOAD_CONST 1 (None) 26 RETURN_VALUE >>> dis("while True: b+=1") 1 0 SETUP_LOOP 13 (to 16) >>3 LOAD_NAME0 (b) 6 LOAD_CONST 0 (1) 9 INPLACE_ADD 10 STORE_NAME 0 (b) 13 JUMP_ABSOLUTE3 >> 16 LOAD_CONST 1 (None) 19 RETURN_VALUE 'while 1' and 'while "exception not raised"' are similarly condensed. This leaves only the initial test of the argument. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
On 12/05/2014 03:30 AM, Fetchinson responded to > Steven D'Aprano's rant of: >> >> Many links are broken. When you click on the broken link, it says that it >> has been reported and will be fixed, but weeks later it remains broken, >> e.g.: >> >> https://www.python.org/doc/essays/metaclasses/Eiffel.py > > What makes you think that this page is ought to return actual content? Could you rephrase that question? The way it's worded at the moment is like going to a restaurant, ordering some food, having the plate of food put in front of you, trying to eat the food and getting nothing but air, and then having the waiter say, "What makes you think there would be actual substance?" > And what would you estimate, how many standard deviations are you away > from the average viewer of python.org in terms of these metrics (where > the metrics are like/dislike of menus, like/dislike of mouse moving, > like/dislike of unexpected browser behavior, like/dislike of links, > like/dislike of slide shows, etc.)? I am reminded of the quote by Edsger W. Dijkstra: Simplicity and elegance are unpopular because they require hard work and discipline to achieve and education to be appreciated. -- ~Ethan~ signature.asc Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
On Fri, Dec 5, 2014 at 4:30 AM, Fetchinson . wrote: > > Many links are broken. When you click on the broken link, it says that it > > has been reported and will be fixed, but weeks later it remains broken, > > e.g.: > > > > https://www.python.org/doc/essays/metaclasses/Eiffel.py > > What makes you think that this page is ought to return actual content? The page at https://www.python.org/doc/essays/metaclasses/ links to it. The fact that something on the same site links to it is a good indication that there ought to be something at the other end of the link. The content that is expected to be found there can still be found at the legacy site: http://legacy.python.org/doc/essays/metaclasses/Eiffel.py -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
>> > Many links are broken. When you click on the broken link, it says that > it >> > has been reported and will be fixed, but weeks later it remains broken, >> > e.g.: >> > >> > https://www.python.org/doc/essays/metaclasses/Eiffel.py >> >> What makes you think that this page is ought to return actual content? > > The page at https://www.python.org/doc/essays/metaclasses/ links to it. The > fact that something on the same site links to it is a good indication that > there ought to be something at the other end of the link. I see, thanks, this was the missing piece of information, I didn't know there are links to that page. Cheers, Daniel > The content that is expected to be found there can still be found at the > legacy site: http://legacy.python.org/doc/essays/metaclasses/Eiffel.py > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
On 12/9/14, Ethan Furman wrote: > On 12/05/2014 03:30 AM, Fetchinson responded to >> Steven D'Aprano's rant of: >>> >>> Many links are broken. When you click on the broken link, it says that >>> it >>> has been reported and will be fixed, but weeks later it remains broken, >>> e.g.: >>> >>> https://www.python.org/doc/essays/metaclasses/Eiffel.py >> >> What makes you think that this page is ought to return actual content? > > Could you rephrase that question? The way it's worded at the moment is like > going to a restaurant, ordering some food, > having the plate of food put in front of you, trying to eat the food and > getting nothing but air, and then having the > waiter say, "What makes you think there would be actual substance?" As Ian pointed out in another message in this thread there is a link on python.org that points to the above page. I did not know this. So when I read that a link is broken, to me it sounded like, hey, there isn't any content at https://python.org/some/bla/bla/bla/random/stuff which made me ask why does the OP think there should be anything. If there are no links to it, it's fine, if there is one (or more) then of course it's not fine. Apparently the case is the latter. Cheers, Daniel > >> And what would you estimate, how many standard deviations are you away >> from the average viewer of python.org in terms of these metrics (where >> the metrics are like/dislike of menus, like/dislike of mouse moving, >> like/dislike of unexpected browser behavior, like/dislike of links, >> like/dislike of slide shows, etc.)? > > I am reminded of the quote by Edsger W. Dijkstra: > > Simplicity and elegance are unpopular because they require > hard work and discipline to achieve and education to be > appreciated. > > -- > ~Ethan~ > > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- https://mail.python.org/mailman/listinfo/python-list
Re: When do default parameters get their values set?
"Dave Angel" wrote: > On 12/08/2014 05:10 PM, bSneddon wrote: >> I ran into an issue setting variables from a GUI module that imports >> a back > end module. My approach was wrong obviously but what is the best way > to set values in a back end module. >> > > To answer the subject line, the default parameter(s) are evaluated > when the function is compiled, and then stored with the function. The function is compiled when the module is compiled. At latest that is when the module is imported (though in most cases it was probably compiled the first time you ran the code and isn't recompiled unless the source code changes). The default parameters are actually evaluated when the 'def' statement is executed and the function object is created from the default arguments and the previously compiled code block. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
On Wed, Dec 10, 2014 at 8:16 AM, Fetchinson . wrote: > As Ian pointed out in another message in this thread there is a link > on python.org that points to the above page. I did not know this. So > when I read that a link is broken, to me it sounded like, hey, there > isn't any content at https://python.org/some/bla/bla/bla/random/stuff > which made me ask why does the OP think there should be anything. If > there are no links to it, it's fine, if there is one (or more) then of > course it's not fine. Apparently the case is the latter. > I believe this is a bug, not a design flaw. There've been a few others like it (PEPs with missing images, for instance), and the best thing to do is raise an issue on the github project page: https://github.com/python/pythondotorg ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: When do default parameters get their values set?
On Tue, Dec 9, 2014, at 16:18, Duncan Booth wrote: > The default parameters are actually evaluated when the 'def' statement is > executed and the function object is created from the default arguments > and > the previously compiled code block. Which means that if you execute the def statement [or lambda] more than once, you will get more than one instance of the default parameter. >>> def f(): return (lambda x={}: x) ... >>> f()() is f()() False >>> g = f() >>> g() is g() True -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Iterables struggling using map() built-in
Terry Reedy wrote: > On 12/9/2014 12:03 AM, Terry Reedy wrote: >>> Roy Smith wrote: >>> Chris Angelico wrote: >> > def myzip(*args): > iters = map(iter, args) > while iters: > res = [next(i) for i in iters] > yield tuple(res) Ugh. When I see "while foo", my brain says, "OK, you're about to see a loop which is controlled by the value of foo being changed inside the loop". > > What is nasty to me is that to understand the loop, one must do a whole > program analysis to determine both that 'iters' is not rebound and that > the list it is bound to is not mutated. When people say "whole program analysis", they usually mean the entire application including all its modules and libraries, not a four line function, excluding the def header. (Or three lines if you get rid of the unnecessary temporary variable 'res'.) Did it take you a long time to read all two lines of the while loop to determine that iters is not modified or rebound? I really think you guys are trying too hard to make this function seem more complicated than it is. If you find it so hard to understand a simple function with four short lines, one wonders how you would possibly cope with real code. Purely by coincidence, I have the source to the "pyclbr" module from the standard library open in a text editor. I see a _readmodule function that looks, in part, like this: try: for tokentype, token, start, _end, _line in g: if ... while ... elif ... while.. if ... if ... if ... else ... elif ... while ... if ... if ... while ... if ... if ... else ... if ... if ... if ... if ... elif ... if ... elif ... elif ... at which point I'm about halfway through the try block and I'm giving up. https://hg.python.org/cpython/file/3.4/Lib/pyclbr.py This, presumably, is good enough for the standard library, but the four line version of zip is supposed to be too hard for mortal man to comprehend. That's funny :-) > To do the later, one must not > only read the loop body, but also preceding code to make sure the list > is not aliased. The preceding code is exactly *one* line, a single assignment binding the name iters to the list. The while loop body is exactly two lines, one if you dump the unnecessary 'res' temporary variable: yield tuple([next(i) for i in iters]) Quite frankly Terry, I do not believe for a second that somebody like you who can successfully maintain IDLE is struggling to understand this myzip() function. Wait... is this like the Four Yorkshire Men sketch from Monty Python, only instead of complaining about how hard you had it as children, you're all trying to outdo each other about how difficult you find it to read this function? If so, well done, you really had me for a while. > Once the logic is clear and 'localized', even a simple compiler like > CPython's can see that this is a loop-forever construct and that the > loop test is unnecessary. So it can be removed. Ah, now that's nice. You're suggesting that by moving the loop condition outside of the while statement, the compiler can generate more efficient byte code. It only needs to test iters once, not at the start of every loop. That is the first interesting argument I've seen so far! On the one hand, as micro-optimizations go, it will be pretty micro. Particularly compared to the cost of starting and stopping a generator, I doubt that will save any meaningful time, at least not enough to make up for the extra effort in having to read and comprehend one more line of code. On the other hand, *premature optimization*. In general, one shouldn't write more complex code so the compiler can optimize it, one should write simpler code and have a smarter compiler. If *we* are capable of recognising that iters is not modified in the body of the loop, then the compiler should be capable of it too. (If it isn't, it is because nobody has bothered to give the compiler sufficient smarts, not because it can't be done.) So a good compiler should be able to compile "while iters" into "if iters: while True" so long as iters is not modified in the body of the loop. Still, that's a nice observation: sometimes more complex source code can lead to simpler byte code. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
Fetchinson . wrote: > So > when I read that a link is broken, to me it sounded like, hey, there > isn't any content at https://python.org/some/bla/bla/bla/random/stuff > which made me ask why does the OP think there should be anything. You should have the courtesy of assuming I'm not a total idiot. Why would I think that https://python.org/some/bla/bla/bla/random/stuff would do anything but give a 404? Even YouTube commentators know that you can't try random stuff into a URL and expect a useful page to appear. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
Chris Angelico wrote: > On Wed, Dec 10, 2014 at 8:16 AM, Fetchinson . > wrote: >> As Ian pointed out in another message in this thread there is a link >> on python.org that points to the above page. I did not know this. So >> when I read that a link is broken, to me it sounded like, hey, there >> isn't any content at https://python.org/some/bla/bla/bla/random/stuff >> which made me ask why does the OP think there should be anything. If >> there are no links to it, it's fine, if there is one (or more) then of >> course it's not fine. Apparently the case is the latter. >> > > I believe this is a bug, not a design flaw. There've been a few others > like it (PEPs with missing images, for instance), and the best thing > to do is raise an issue on the github project page: > > https://github.com/python/pythondotorg The flaw is that when you get a 404, it claims that the maintainers have been notified, but they apparently don't do anything about it. They should be fixing broken links without waiting for somebody to raise an issue. Otherwise, what's the point of being notified? It's actually worse than that. By telling the end user that the maintainers have been notified, they *discourage* people from raising an issue. Why raise an issue for something that is already being attended too? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Iterables struggling using map() built-in
On Wed, Dec 10, 2014 at 11:10 AM, Steven D'Aprano wrote: > On the other hand, *premature optimization*. In general, one shouldn't write > more complex code so the compiler can optimize it, one should write simpler > code and have a smarter compiler. If *we* are capable of recognising that > iters is not modified in the body of the loop, then the compiler should be > capable of it too. (If it isn't, it is because nobody has bothered to give > the compiler sufficient smarts, not because it can't be done.) So a good > compiler should be able to compile "while iters" into "if iters: while > True" so long as iters is not modified in the body of the loop. In general, one can't expect the boolification of a Python object to be consistent, so the compiler can't optimize this. How can it be sure the list will never become empty? I'm still of the opinion that a while loop's header implies something about the code; "while iters:" implies that iters might be able to become false. Sure, you can verify easily enough that it never will... but why should you have to verify at all? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Iterables struggling using map() built-in
On 10/12/2014 00:10, Steven D'Aprano wrote: Wait... is this like the Four Yorkshire Men sketch from Monty Python, only instead of complaining about how hard you had it as children, you're all trying to outdo each other about how difficult you find it to read this function? If so, well done, you really had me for a while. The Four Yorkshiremen was not actually a Monty Python sketch. Get it right, lad :) -- 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: Do you like the current design of python.org?
On Wed, Dec 10, 2014 at 11:16 AM, Steven D'Aprano wrote: > The flaw is that when you get a 404, it claims that the maintainers have > been notified, but they apparently don't do anything about it. They should > be fixing broken links without waiting for somebody to raise an issue. > Otherwise, what's the point of being notified? > > It's actually worse than that. By telling the end user that the maintainers > have been notified, they *discourage* people from raising an issue. Why > raise an issue for something that is already being attended too? Okay, *that* is a design flaw. Though personally, I never believe those "maintainers have been notified" pages. I mean, anyone can go looking at their server error logs, but how many people *get notified*?? And when does it *ever* result in prompt fixing of errors? So even if this is the one site on the entire internet where that's true, I'd be inclined to drop that text, because it's pretty much useless. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
Chris Angelico wrote: > On Wed, Dec 10, 2014 at 11:16 AM, Steven D'Aprano > wrote: >> The flaw is that when you get a 404, it claims that the maintainers have >> been notified, but they apparently don't do anything about it. They should >> be fixing broken links without waiting for somebody to raise an issue. >> Otherwise, what's the point of being notified? >> >> It's actually worse than that. By telling the end user that the maintainers >> have been notified, they *discourage* people from raising an issue. Why >> raise an issue for something that is already being attended too? > > Okay, *that* is a design flaw. Though personally, I never believe > those "maintainers have been notified" pages. I mean, anyone can go > looking at their server error logs, but how many people *get > notified*?? And when does it *ever* result in prompt fixing of errors? > > So even if this is the one site on the entire internet where that's > true, I'd be inclined to drop that text, because it's pretty much > useless. It seems to me that text can't be useless. Either it is useful (because it conveys correct information) or it is harmful (because it keeps visitors from submitting an explicit bug report). -- Christoph M. Becker -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
On Wed, Dec 10, 2014 at 11:43 AM, Christoph M. Becker wrote: >> So even if this is the one site on the entire internet where that's >> true, I'd be inclined to drop that text, because it's pretty much >> useless. > > It seems to me that text can't be useless. Either it is useful (because > it conveys correct information) or it is harmful (because it keeps > visitors from submitting an explicit bug report). I should have said "useless at best". If this is the one site on the internet where this is actually true, people like me will still ignore it because there are just so many where it's not the case, and so the words are useless. Carrying correct information that nobody believes is not truly useful. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: When do default parameters get their values set?
On Wednesday, December 10, 2014 4:38:18 AM UTC+5:30, rand...@fastmail.us wrote: > On Tue, Dec 9, 2014, at 16:18, Duncan Booth wrote: > > The default parameters are actually evaluated when the 'def' statement is > > executed and the function object is created from the default arguments > > and > > the previously compiled code block. > > Which means that if you execute the def statement [or lambda] more than > once, you will get more than one instance of the default parameter. > > >>> def f(): return (lambda x={}: x) > ... > >>> f()() is f()() > False > >>> g = f() > >>> g() is g() > True Nice example -- thanks. Elaborates the why of this gotcha -- a def(inition) is imperative. >From a semantic pov very clean. >From an expectation pov always surprising. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Iterables struggling using map() built-in
In article <54878f8a$0$13010$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > I really think you guys are trying too hard to make this function seem more > complicated than it is. If you find it so hard to understand a simple > function with four short lines, one wonders how you would possibly cope > with real code. Well, look at it this way. You've got several folks here (I count Terry, Ned, Chris, and myself) all saying, "We find this confusing", and you're saying, "nobody should find this confusing". I suppose one possible explanation for this dichotomy is that we're all incapable of dealing with real code. Yeah, that must be it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
"Christoph M. Becker" writes: > It seems to me that text can't be useless. Either it is useful > (because it conveys correct information) or it is harmful (because it > keeps visitors from submitting an explicit bug report). In the latter case, if the text is harmful, that doesn't disqualify it from also being useless. -- \ “If you define cowardice as running away at the first sign of | `\ danger, screaming and tripping and begging for mercy, then yes, | _o__) Mr. Brave man, I guess I'm a coward.” —Jack Handey | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Ftplib.FTP_TLS Ports
We are trying to open our firewall but it keeps failing. The docs state that the default port is 21 and we've opened port 21. I've ran tcpdump on the box while running the script. I see a destination port of 21, but there seems to be random destination ports such as 2320 which follow. If we open the firewall to allow all traffic, the script works. Here is a snip of what I have for the ftp portion. Any ideas would be helpful. import ftplib session = ftplib.FTP_TLS('xxx.ftp.com','user','password') file = open('Bkup.tar.gz','rb') session.storbinary('STOR Bkup.tar.gz', file) file.close() session.quit() Thanks! Eric -- https://mail.python.org/mailman/listinfo/python-list
Re: Ftplib.FTP_TLS Ports
On Wed, Dec 10, 2014 at 3:13 PM, Eric wrote: > We are trying to open our firewall but it keeps failing. The docs state > that the default port is 21 and we've opened port 21. I've ran tcpdump on > the box while running the script. I see a destination port of 21, but there > seems to be random destination ports such as 2320 which follow. If we open > the firewall to allow all traffic, the script works. Here is a snip of what > I have for the ftp portion. Any ideas would be helpful. > > import ftplib > > session = ftplib.FTP_TLS('xxx.ftp.com','user','password') > file = open('Bkup.tar.gz','rb') > session.storbinary('STOR Bkup.tar.gz', file) > file.close() > session.quit() FTP works with two (or more) connections: one on the control port, and one (or more) on data ports. You'd have to check out what the server is using for data ports, and then open that range. For instance, it might be configured to use 2300-2350 for data ports, in which case you could permit all of those ports. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Ftplib.FTP_TLS Ports
On Wed, Dec 10, 2014 at 3:37 PM, Dennis Lee Bieber wrote: > Are you running in PASSIVE mode? > > Original (normal?) FTP uses the known numbered port as a control port, > and gets a second port for the data itself (without looking up the RFC I > can't state if said second port is opened by the server in response to the > client connect, or is provided to the server by the client). > > Passive mode, as I understand it, basically means the control port is > used for everything -- it explicitly is used to get through firewalls. Passive mode is easier for getting through firewalls, especially at the client side, but that's not exactly how it works. In active mode (the default for the protocol, though a lot of clients these days default to requesting passive mode), the FTP client listens on a port and the FTP server connects to that port for data transmission - inverting the usual server/client interaction. The client can either listen on port 22, or listen on any other port and send the server the details (the latter being much more common). In passive mode, the server listens on an additional port, and sends the client the details. The client then connects to that port, usually on the same host as the control port, but a high number. Passive mode is much easier for a client-side firewall; it can usually traverse a defaultly-configured home grade NAT firewall, for instance. Active mode is slightly easier for a server-side firewall, though the difference isn't huge (you just have to open up an additional port range and tell the FTP server which ports to use). If it weren't for a few mindbogglingly backward clients like the default Windows FTP, there'd be virtually no reason to bother supporting active mode any more. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you like the current design of python.org?
On 05Dec2014 18:05, Ian Kelly wrote: On Fri, Dec 5, 2014 at 3:43 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: It requires Javascript or else basic functionality fails. In what way does basic functionality fail? I just tried loading the page with Javascript disabled and it seemed fine. Hmm. Loading https://www.python.org/download/releases/2.2/descrintro/ without javascript: - at the top right the "AA", "Socialize" and "Sign In" labels have menu dropdowns exposed below them, downless covering... something. - the AA menu buttons are all dysfunctional, being purely javascript; it would be better if the menu was styled "display=none" by default, and made visible by javascript There are also the disappointingly common placeholder characters in various place, for example to the left of each item in the "Socialize" menu. These look like this: href="http://plus.google.com/+Python";> class="icon-google-plus">Google+ so I'm suppose this is some failed style sheet. [...] It looks like this may NoScript blocking a font load directive. [...] Yup. Cheers, Cameron Simpson The batsmen out there should know something about the game. - Michael Holding, Aus vs West Indies commentator -- https://mail.python.org/mailman/listinfo/python-list
Nested loops is strangely slow, totally at a loss.
When doing nested loop, the very first iteration of the innermost loop ends ultimately slow. Let's the code speak. The following code is quite contrived. Actually it's derived from my 3d-dct script. The actual difference is way more significant than this example. In case of any evil of gmail, bpaste here: https://bpaste.net/show/edfef62edb17 # this constructs a space_len x space_len x space_len 3D coordinate import timeit from itertools import product space_len = 580 space = product(xrange(space_len), xrange(space_len), xrange(space_len)) sparse_cloud = product(xrange(1), xrange(1), xrange(1)) for i, j, k in sparse_cloud: ts = timeit.default_timer() if (i, j, k) in space: pass te = timeit.default_timer() print("A, finish a loop with ", te-ts) print("Done Test A") sparse_cloud = product(xrange(1000), xrange(1000), xrange(1000)) for i, j, k in sparse_cloud: ts = timeit.default_timer() if (i, j, k) in space: pass te = timeit.default_timer() print("B, finish a loop with ", te-ts) print("Done Test B") # example output """ ('A, finish a loop with ', 2.1457672119140625e-06) Done Test A ('B, finish a loop with ', 8.736134052276611) ('B, finish a loop with ', 1.9073486328125e-06) ('B, finish a loop with ', 0.0) ('B, finish a loop with ', 0.0) ('B, finish a loop with ', 1.1920928955078125e-06) ('B, finish a loop with ', 9.5367431640625e-07) ('B, finish a loop with ', 9.5367431640625e-07) ... """ We can see that the first iteration of B ends rather slow, 8.7 seconds here. Why? I am curious about the internals, what's happening under the hood that makes this happen? Thanks in advance! -- Shiyao Ma http://introo.me -- https://mail.python.org/mailman/listinfo/python-list
Re: Nested loops is strangely slow, totally at a loss.
One thing to note, the logic of using "in" is not of concern here. This is a *contrived* example, the problem is the slowness of the first iteration. -- https://mail.python.org/mailman/listinfo/python-list
Re: Nested loops is strangely slow, totally at a loss.
On Wed, Dec 10, 2014 at 4:20 PM, Shiyao Ma wrote: > from itertools import product > space_len = 580 > space = product(xrange(space_len), xrange(space_len), xrange(space_len)) > > sparse_cloud = product(xrange(1000), xrange(1000), xrange(1000)) > for i, j, k in sparse_cloud: > ts = timeit.default_timer() > if (i, j, k) in space: pass > te = timeit.default_timer() On Wed, Dec 10, 2014 at 4:23 PM, Shiyao Ma wrote: > One thing to note, the logic of using "in" is not of concern here. > This is a *contrived* example, the problem is the slowness of the first > iteration. Are you sure it isn't? Your 'space' is an iterable cubic cross-product. Your first loop checks (0,0,0) which is the first element returned, and is thus fast... but it also *consumes* that first element. The next time you test it, the entire space gets consumed, looking for another (0,0,0), which won't exist. That means iterating over 580**3 == 195112000 (two hundred million) tuples, and that *is* going to be slow. Is product() really the right way to represent your space? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Nested loops is strangely slow, totally at a loss.
On Wed, 10 Dec 2014 13:20:25 +0800, Shiyao Ma wrote: > When doing nested loop, the very first iteration of the innermost loop > ends ultimately slow. > > Let's the code speak. > > The following code is quite contrived. Actually it's derived from my > 3d-dct script. The actual difference is way more significant than this > example. > > In case of any evil of gmail, bpaste here: > https://bpaste.net/show/edfef62edb17 > > # this constructs a space_len x space_len x space_len 3D coordinate > import timeit > from itertools import product > space_len = 580 > space = product(xrange(space_len), xrange(space_len), xrange(space_len)) space will contain 580**3 == 195112000 items, but they are lazily generated. Once you access an item, it is gone, never to be seen again (until you recreate the product iterator object). > sparse_cloud = product(xrange(1), xrange(1), xrange(1)) This, on the other hand, only has a single item, (0,0,0). When you run this: > for i, j, k in sparse_cloud: > ts = timeit.default_timer() > if (i, j, k) in space: pass > te = timeit.default_timer() > print("A, finish a loop with ", te-ts) > print("Done Test A") it tests: (0,0,0) in space which matches the very first item of space, which takes hardly any time at all. But having done this, you have consumed that first value. > sparse_cloud = product(xrange(1000), xrange(1000), xrange(1000)) for i, > j, k in sparse_cloud: > ts = timeit.default_timer() > if (i, j, k) in space: pass > te = timeit.default_timer() > print("B, finish a loop with ", te-ts) > print("Done Test B") Now you create a new sparse_cloud iterator, and iterate over it. The first loop gets i, j, k = 0, 0, 0 and then tried to check: (0,0,0) in space *but* that item from has already been consumed. So it now runs through the rest of the iterator: (0,0,0) == (0,0,1) # False (0,0,0) == (0,0,2) # False (0,0,0) == (0,0,3) # False ... (0,0,0) == (0,0,579) # False (0,0,0) == (0,1,0) # False (0,0,0) == (0,1,1) # False ... (0,0,0) == (579,579,579) # False which takes a long time. Now the next loop gets the values: i, j, k = 0, 0, 1 and then tried to check: (0,0,1) in space but space is now exhausted, and it returns False immediately. And so on for the rest of the sparse_cloud iterator. It would be nice if product iterators behaved like xrange() objects and could perform "in" tests without exhausting the iterator, but they don't. That's sad. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: serial data and web
On 12/10/2014 07:28 AM, Dennis Lee Bieber wrote: On Tue, 09 Dec 2014 14:24:51 +0100, manduk declaimed the following: "A web page"? Did you mean a Web server? ok I mean I would like to view the datas on a web page Basically, you'll have to upload your data to a Web Server, then the server will serve your data. Depending on how your server is setup, you'll have to use FTP, RSync, HTTP GET or POST or PUT,... There is plenty of ways to upload some content. not only upload in a folder of a webserver...I wish to see in real time the datas in a public html page. I get the data from serial port and then I put them in a remote page. Which is the best way to transfer datas from a text file for example and send it on web? Normal HTML is a "pull" technology... The client (browser) has to ask the server to send it the page. To have dynamically updating web page requires either: a web page that does a timed redirect back to itself (going to be very annoying as the page keeps reloading at whatever interval was given to the redirect), OR the use of Javascript to modify the HTML during the load, OR Javascript to modify pages in real-time -- cf: http://en.wikipedia.org/wiki/Dynamic_HTML and http://en.wikipedia.org/wiki/Ajax_%28programming%29 Which is a loop for pulling. There is another alternative: Websockets. But it is still a "young" technolgy. -- https://mail.python.org/mailman/listinfo/python-list
Re: Nested loops is strangely slow, totally at a loss.
On Wed, Dec 10, 2014 at 5:44 PM, Steven D'Aprano wrote: > It would be nice if product iterators behaved like xrange() objects and > could perform "in" tests without exhausting the iterator, but they don't. > That's sad. It'd be very difficult to do that in the general sense. But it should be possible to have a multi-dimensional range object that behaves the way Py3's range object does, including membership tests and stuff. (Might already exist, for all I know.) That would do what the OP wants, I think. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Nested loops is strangely slow, totally at a loss.
On Tue, Dec 9, 2014 at 11:30 PM, Chris Angelico wrote: > Are you sure it isn't? Your 'space' is an iterable cubic > cross-product. Your first loop checks (0,0,0) which is the first > element returned, and is thus fast... but it also *consumes* that > first element. The next time you test it, the entire space gets > consumed, looking for another (0,0,0), which won't exist. That means > iterating over 580**3 == 195112000 (two hundred million) tuples, and > that *is* going to be slow. Huh, I wasn't even aware that membership tests worked on iterables with no __contains__ method. Seems odd to me that 'x in y' should be supported but not 'len(y)'. -- https://mail.python.org/mailman/listinfo/python-list
Re: Nested loops is strangely slow, totally at a loss.
On 12/10/2014 1:53 AM, Chris Angelico wrote: On Wed, Dec 10, 2014 at 5:44 PM, Steven D'Aprano wrote: It would be nice if product iterators behaved like xrange() objects and could perform "in" tests without exhausting the iterator, but they don't. That's sad. It'd be very difficult to do that in the general sense. But it should be possible to have a multi-dimensional range object that behaves the way Py3's range object does, including membership tests and stuff. (Might already exist, for all I know.) That would do what the OP wants, I think. Itertools are general tools for building specialized objects. itertools.product provides the iter method. class ReitProd(): # untested def __init__(self, reiterable, n): self.reit = reiterable # must support 'in' self.n = n def __iter__(self): return itertools.product(self.reit, repeat=self.n) def __contains__(self, seq): if len(seq) != self.n: return False for i, item in enumerate(it): if item not in self.reit: return False return True -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Nested loops is strangely slow, totally at a loss.
On Wed, 10 Dec 2014 17:53:05 +1100, Chris Angelico wrote: > On Wed, Dec 10, 2014 at 5:44 PM, Steven D'Aprano > wrote: >> It would be nice if product iterators behaved like xrange() objects and >> could perform "in" tests without exhausting the iterator, but they >> don't. That's sad. > > It'd be very difficult to do that in the general sense. But it should be > possible to have a multi-dimensional range object that behaves the way > Py3's range object does, including membership tests and stuff. (Might > already exist, for all I know.) That would do what the OP wants, I > think. Oh yes. If the product object has n-ordinates, then you could implement it something vaguely like this: def contains(product_obj, item): if not isinstance(item, tuple): return False if len(item) != number_of_ordinates: return False for i, x in enumerate(item): if x not in ordinate[i]: return False return True but note that this too might exhaust the product iterator, if it is constructed from iterators! But for the case whether it is constructed from xrange objects, lists, tuples, etc. it would work fine. Strings are another funny case: consider what happens here: ("bc", "x", "1") in product("abcd", "wxyz", "1234") It should return False, but since string containment tests operate on substrings not just single characters, it will wrongly return True. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
[RELEASE] ‘python-daemon’ version 1.5.6 released
Howdy all, I am pleased to announce the release of version 1.5.6 of the ‘python-daemon’ library. The current release is always available at https://pypi.python.org/pypi/python-daemon/>. The project's forums and VCS are hosted at Alioth https://alioth.debian.org/projects/python-daemon/>. Significant changes since the previous version == * Declare a maximum dependency on ‘lockfile’ < 0.9. Only version 0.8.x of ‘lockfile’ will work with ‘python-daemon’ 1.5.x. * Update package homepage to the current Alioth hosted project page. * Specify versions of Python supported, as trove classifiers. * The library is now licensed under Apache License version 2.0. The packaging is now licensed under GNU General Public License version 3 or later. * The documentation is now included with the distribution, in the ‘doc/’ directory. * Multiple changes to prepare for Python 3 migration. What is the ‘python-daemon’ library? ‘python-daemon’ is a Python library to implement a well-behaved Unix daemon process. -- \ “Not to perambulate the corridors in the hours of repose in the | `\ boots of ascension.” —ski hotel, Austria | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list