Re: Python for philosophers
On 05/18/2013 08:30 PM, 8 Dihedral wrote: > I am too lazy to write a factorial computations with primes > here. Ahh, that's better. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using ACLs in JSON
On 05/24/2013 02:18 AM, Peter Brooks wrote: > I'm designing a system that should allow different views to different > audiences. I understand that I can use application logic to control > the access security, but it seems to me that it'd make more sense to > have this documented in the data-stream so that it's data-driven. > > I was wondering if there was any standard way of doing this in JSON. > Alternatively, is there a better way of organising this in Python > that's compatible with JSON? While I don't understand exactly what you're using JSON for, and nor do I understand the purpose of the JSON structure you posted, I can say that ACLs have nothing to do with JSON. JSON is simply a data markup format, like HTML, XML, plain text, or an INI file. It's merely data. If you want to restrict who sees what when they request a chunk of data formatted using JSON, then you have to enforce that in the code that's processing the request for data using another mechanism. And that mechanism depends on how your clients ask for JSON data, and what code is serving or generating the JSON data. -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 05/26/2013 11:43 AM, Wolfgang Keller wrote: > And just like HTML never was a valid GUI framework and never will be > one, HTTP will never be a suitable transport layer for a RPC protocol. On good thing web development has brought us is the knowledge that modularization and layers are a brilliant idea. Your back end exposes services and business logic, and your front end can be in HTMLv5 and Javascript, or QtQuick, PyGTK, or Visual Studio. If you do need a native interface, it's a heck of a lot easier to rewrite just the frontend then the entire stack. Who cares how the RPC is done; that's an implementation detail. HTTP does happen to work well though. Why do you say it is not suitable? > From the description this looks like a simble database CRUD > application. Somethign like that is definitely easier to implement and > to deploy and a *lot* more functional with any of the RAD frameworks > available for Python. Chuckle. Simple CRUD, eh. Almost all apps involve database CRUD interactions. And often in highly complex ways using business logic. Maybe it would have been faster to develop, but ultimately less useful and require more development time in the long run. suppose I now want the app natively on my phone (because that's all the rage). It's an iPhone. Oh. Apple doesn't support Python. Okay, rewrite the works, including business logic, in Objective C. Now I want it on my android phone. Oops rewrite the stack again in Java. Since his application by nature is network oriented (client/server I presume since he mentions multiple users), sticking it on a web server and having the front end be separate (be it HTML or not) gives him the flexibility to rapidly build native "screenable" UIs for his app on any platform he chooses, something your philosophy does not allow for. -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 05/26/2013 01:45 PM, Roy Smith wrote: > In article , > Michael Torrie wrote: > >> On good thing web development has brought us is the knowledge that >> modularization and layers are a brilliant idea. > > Modularization and layers were a brilliant idea long before the web came > around. True. Though it seems like it fell out of fashion for a long time. I went to school before the advent of web development and though we talked about modularization and coupling in software engineering, really it was all rather monolithic. Web development changed our focus back to where it should have been all along. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/26/2013 11:06 PM, Νίκος Γκρ33κ wrote: > But iu have it set up for 'utf-8' as seen in this statement. > > con = pymysql.connect( db = 'metrites', host = 'localhost', user = > 'me', passwd = 'somepass', charset='utf-8', init_command='SET NAMES UTF8' ) That might not help... see below. > > Yoiu mean i shoudl chnag eit to greek isoo= (iso-8859-7) > but then i store english names and greek names as well, so it has to be a > utf-8. Right. UTF-8 is the encoding you want. I think your problem is that when the MySQL database was created, it was not created using the UTF-8 mode, but rather latin-1 (despite your init_command which has nothing to do with database creation). You'll want to recreate the database and make double sure you've selected the right character set and collation: http://dev.mysql.com/doc/refman/5.0/en/charset-applications.html At least that should be your first step in debugging this problem. If the database is indeed utf-8, then you can move on to debugging why the python code is choosing latin-1 to encode your query string. That's my two-cents for today. -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 05/27/2013 09:31 AM, Wolfgang Keller wrote: >> HTTP handles that just fine, with your choice of XML, > > And XML is definitely not suitable as a marshalling format for a RPC > protocol. > > XML-over-HTTP is a true cerebral flatulance of some hopelessly clueless > moron. Hmm. Well I think there are a lot of very smart developers that are using xml to marshal rpc and it's working fine. So either they know something you don't, or maybe they are just busy making code that functions and functions pretty well, instead of making inflammatory statements on USENET. Sure XML is not very efficient or compact, but it does handle unicode intrinsically through standard encodings, and a plethora of parsers makes it a decent choice. It's like what they say about the book: "for though it has many omissions and contains much that is apocryphal, or at least wildly inaccurate, it scores over the older, more pedestrian work in two important respects. First, it is slightly cheaper; and second, it has the words Don't Panic inscribed in large friendly letters on its cover." I've used LBER-encoded wire protocol before, and it was fine, but hard to debug on the wire, and didn't haven anything in it to handle unicode except base64-encoding utf8 byte streams. That said, all this reminds me of a good saying, "XML is like violence; if it doesn't solve your problem you're not using enough of it." Fortunately none of this really matters. Who cares what is used to marshall RPC over the wire? As a developer I certainly don't care. I'll use whatever is convenient and well supported. One reason I do like xmlrpc, though, because it's pretty much available to all web-based back ends for free (or at little cost) and you don't need to set up a special server process to handle it, or deal with odd port numbers that might be blocked, doing ssl yourself, etc. Having HTTP do the transport frees me from having to worry about all that, since in the case of a web app I am already using a web server. -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 05/27/2013 09:22 AM, Wolfgang Keller wrote: >> suppose I now want the app natively on my phone (because that's all >> the rage). It's an iPhone. Oh. Apple doesn't support Python. >> Okay, rewrite the works, including business logic, in Objective C. >> Now I want it on my android phone. > > Those are gadgets, not work tools. As a professional programmer I'm afraid you're going to soon find yourself out of work if you really see things that way. I honestly used to feel that way about graphical user interfaces. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/27/2013 02:17 PM, Νίκος Γκρ33κ wrote: > I have checked the database through phpMyAdmin and it is indeed UTF-8. > > I have no idea why python 3.3.1 chooses to work with latin-iso only It's not python that is doing this here... If you look at the source code to pymysql, I'm sure you will identify the problem. In fact I'll even walk you through things. The traceback you posted tells you what's going on and why, with superfluous details removed for clarity: File "/opt/python3/lib/python3.3/site-packages/pymysql/cursors.py", line 108, in execute: query = query.encode(charset) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 46-52: ordinal not in range(256) So there we have it. pymysql is actually explicitly calling .encode() on a string and is using whatever character set is specified by the local variable charset. If you look in cursors.py at that line, and then a few lines above, you will find that charset is assigned to conn.charset. This means that the charset is actually defined in the connection object. So go look at connections.py. Sure enough, it shows that charset is defined by default as "latin-1." That's no good for you. So take a look at the __init__ method in connections.py. In there you should find the necessary keyword argument you need to use when creating the mysql connection to make sure the charset is utf-8. -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
On 05/28/2013 09:32 AM, JackM wrote:
> Having a problem getting a py script to execute. Got this error:
>
> File "/scripts/blockIPv4.py", line 19
> ip = line.split(';')[0]
> ^
> IndentationError: expected an indented block
> I'm perplexed because the code that the error refers to *is* indented:
> with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile:
> for line in inFile.readlines():
> ip = line.split(';')[0]
> output = os.popen( '/etc/sysconfig/iptables -A INPUT -s ' + ip
> + ' -j REJECT' )
> logFile.write(ip+' - Has been blocked\n')
>
>
> What am I missing here?
Indentation has to be consistent. likely the for line is indented with
spaces and the next line with a tab. You can use tabs and spaces, but
you have to be consistent with how you use them. IE if level 1 is
indented with spaces, then level 2 has to be indented with spaces up to
level 1 as well. Hope that makes sense.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/28/2013 10:00 AM, Νίκος Γκρ33κ wrote: > I do not know here to find connections.py Michael. It's part of the pymysql package that you installed. Look in there (the traceback even shows you where the file is). But you actually don't even need to look at it on your server. You can see the source code for it here: https://github.com/petehunt/PyMySQL/tree/master/pymysql > But i do not understand since iam suing the following 2 statements, > why a unicode error remains. The traceback told you why the error is happening. inside the pymysql library, there is a call to .encode(charset) on your query string. And the default charset is latin-1. You've got to work out a way to change that and I've already told you exactly how to find out what you need to do. > #needed line, script does *not* work without it sys.stdout = > os.fdopen(1, 'w', encoding='utf-8') > > # connect to database con = pymysql.connect( db = 'pelatologio', host > = 'localhost', user = 'myself', passwd = 'mypass', init_command='SET > NAMES UTF8' ) cur = con.cursor() HINT: this line ^^ is what you have to modify by passing in a particular keyword argument that sets the character set (no it's not the init_command one). You will have to look at connections.py's __init__ declaration and you should see what you need to pass in. Yes I could have saved myself a lot of time and typing by giving you the answer, but that isn't going to help you. On the other hand, if you want the easy way out, paypal some money to me and I'll just give you the answer instead of trying to give you the tools you need to debug this issue. The answers are all in the source code to pymysql, which is open source so you can always read (either on your own server file system or on the git repository). > > Shall i chnage the connector form 'pymysql' => 'MySQLdb' ? No. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/28/2013 10:45 AM, Νίκος Γκρ33κ wrote:
> con = pymysql.connect( db = 'pelatologio', host = 'localhost', user =
> 'blabla', passwd = 'blabla', init_command='SET NAMES UTF8', charset = 'utf-8'
> )
>
> produces this "God knows what" error traceback
Hey at least your database code is now working.
> /home/nikos/public_html/cgi-bin/metrites.py in ()
> 217 template = htmldata + counter
> 218 elif page.endswith('.py'):
> => 219 htmldata = subprocess.check_output(
> '/home/nikos/public_html/cgi-bin/' + page )
> 220 template = htmldata.decode('utf-8').replace(
> 'Content-type: text/html; charset=utf-8', '' ) + counter
> 221
> htmldata undefined, subprocess = '/opt/python3/lib/python3.3/subprocess.py'>, subprocess.check_output =
> , page = 'pelatologio.py'
> /opt/python3/lib/python3.3/subprocess.py in check_output(timeout=None,
> *popenargs=('/home/nikos/public_html/cgi-bin/pelatologio.py',), **kwargs={})
> 584 retcode = process.poll()
> 585 if retcode:
> => 586 raise CalledProcessError(retcode, process.args,
> output=output)
> 587 return output
> 588
> global CalledProcessError = , retcode
> = 1, process = , process.args =
> '/home/nikos/public_html/cgi-bin/pelatologio.py', output = b'\n\n'
> CalledProcessError: Command '/home/nikos/public_html/cgi-bin/pelatologio.py'
> returned non-zero exit status 1
> args = (1, '/home/nikos/public_html/cgi-bin/pelatologio.py')
> cmd = '/home/nikos/public_html/cgi-bin/pelatologio.py'
> output = b'\n\n'
> returncode = 1
> with_traceback = object>
Again the traceback is telling you where to look for the problem. And
the problem is in your own script, pelatologio.py, though the line
number that's causing the problem is obscured.
Basically you want pelatologio.py to run and then you process the output
through a template, correct?
Well the traceback is telling you that pelatologio.py is erroring out.
In fact, subprocess is telling you that this process (your script) quit
with an error. Though the line number in pelatologio.py is unknown (the
traceback is obscured by your html processing code in your template
processor), the error message itself is not. Inside pelatologio.py
there is some object that you are trying to reference the "id" attribute
on it does not contain id.
So the problem is in pelatologio.py. Double check your code there. Try
to make a standalone test file you can run locally.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 05/28/2013 11:26 AM, Wolfgang Keller wrote: >> Please give me an example of a "suitable transport layer for a RPC >> protocol". > > I won't give you an example, but just some very basic criteria: > > - It must be very efficient for very small "datagrams" I won't argue for XML here, but sometimes space efficiency is simply a premature optimization. > - It must provide connections How would you do this? Connections can and do get dropped regularly. To rebuild connections you need another layer to track them. > - For asynchronous programming it must provide for callbacks What do you mean by this? A transport layer has nothing to do with callbacks. All a client can do is make the call, and wait for the answer. The client library can make it look asynchronous of course. And I suppose one could implement an RPC system using UDP where answer packets are dispatched as they come in. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/28/2013 12:08 PM, [email protected] wrote: > Τη Τρίτη, 28 Μαΐου 2013 8:17:05 μ.μ. UTC+3, ο χρήστης Michael Torrie > έγραψε: > >> Basically you want pelatologio.py to run and then you process the >> output through a template, correct? > > That is correct. > >> Inside pelatologio.py there is some object that you are trying to >> reference the "id" attribute on it does not contain id. So the >> problem is in pelatologio.py. Double check your code there. Try >> to make a standalone test file you can run locally. > > I have, i see no error, the error appears only when i append the > charset directive into the connector, if i remove it the error > dissapears. No, when you remove the charset directive your database call fails and thus things fail even earlier. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/29/2013 04:30 AM, [email protected] wrote: > What makes us o sure it is a pymysql issue and not python's encoding > issue? The original traceback, which showed that the encoding error was happening in "/opt/python3/lib/python3.3/site-packages/pymysql/cursors.py", line 108. As was said, you solve that by passing a charset="utf-8" to the connection string. So doing that solved the encoding problem (a query is now being successfully built and sent to mysql) and went on to expose another problem (bug) in your code, but I cannot tell what that is, since the error happened in a subprocess and the traceback got sent to /dev/null. I suspect is has something to do with how the query results are being returned, or it could have something to do with the query itself. Python DB API does not specify exactly which style of prepared statements should be used by a given third-party module. So differences in syntax between how pymysql and MysqlDB define the variables could be the problem. In any case your course is clear. Run pelatologio.py outside of your templating system and see what the traceback says exactly now that the charset issue is fixed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/30/2013 05:47 AM, Νίκος Γκρ33κ wrote: > The moen i switched "charset = 'utf-8'" => "charset = 'utf8'" all > started to work properly! Glad you have it working. Perhaps this should be a lesson to you, Nick. Chris was able to spot your problem by READING THE DOCUMENTATION, which he probably found through some quick searching on Google. These are things you can and should do too. As well as looking at the source code of the modules you may have downloaded and are using, and understanding how the code works (or fits together) and how to debug. You seem to have a tendency to try to attack your problems with rather blunt instruments, and then come to the list where one of the list members invariable does the footwork for you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/30/2013 08:40 AM, Chris Angelico wrote: > but if he's actively using the module, he probably knows where to > find its docs. One would hope, but alas one probably hopes in vain. I'm not sure he wants to spend the time to read the code he's using and understand. He's in too much of a hurry to simply get a result. -- http://mail.python.org/mailman/listinfo/python-list
Re: How clean/elegant is Python's syntax?
On 05/30/2013 12:18 AM, Steven D'Aprano wrote: > In some ways, Python is a more pure OOP language than Java: everything in > Python is an object, including classes themselves. > > In other ways, Python is a less pure and more practical language. You > don't have to wrap every piece of functionality in a class. Python > encourages you to write mixed procedural, functional and object oriented > code, whatever is best for the problem you are trying to solve, which is > very much in contrast to Java. Depending on your understanding of what object-oriented means, procedural and functional code is still object-oriented. In fact modules (the "file") are in essence singleton objects that define attributes, but in practice there can only be one instance of this object (module). Seems like in Java a lot of code is needed to implement singletons (factory, etc). module-level code (procedural code) could simply be thought of as singleton initialization/constructor code that's automatically run when the singleton is created, using import or __import__(). At the function level, a simple function is still an object that implements callable. Python's implementation of OO isn't quite smalltalk pure, but it is much more consistent than in Java or C++. But yes, Python does not force you to shoe-horn your programming into one particular pattern. -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-circuit Logic
On 05/30/2013 07:10 PM, Nobody wrote: > This is why technical drawings which include regularly-spaced features > will normally specify the positions of features relative to their > neighbours instead of (or as well as) relative to some origin. If I am planting trees, putting in fence posts, or drilling lots of little holes in steel, I am actually more likely to measure from the origin (or one arbitrary position). I trust that the errors accumulating as the tape measure marks were printed on the tape is less than the error I'd accumulate by digging a hole, and measuring from there to the next hole. And definitely when drilling a series of holes I'll never measure hole to hole to mark. If I measure from the origin than any error for the hole is limited to itself as much as possible rather than passing on the error to subsequent hole positions. If I was making a server rack, for example, having the holes consistently near their desired position is necessary. Tolerances are such that my hole can be off by as much as a 1/16" of inch of my desired position and it would still be fine, but not if each hole was off by an additional 1/16". I guess what I've described is accuracy vs precision. In the case of the server rack accuracy is important, and precision can be more coarse depending on the screw size and the mount type (threaded hole vs square hole with snap-in nut). -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On 05/31/2013 09:20 AM, Νικόλαος Κούρας wrote: > Why so many pythons in my system. Now in the case of my Python3 > installation, it looks like i have two parallel installations of > Python3, but i don't. One is almost certainly a symlink to the other > and not an actual installation. Well is it a symlink? > I'm thinking of: > > yum remove python > yum remove python3 > yum remove python3.3 What a fantastic way to completely break your os! Python 2 is is a deep dependency of CentOS. You cannot remove it. Python3 and 3.3 can be removed of course. -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On 05/31/2013 12:02 PM, Νικόλαος Κούρας wrote: > please tell me how to unistall python 2.6 and just keep 2.7 > and install 3.3.2 please uisng yum. Python 2.6 is required for CentOS to function. You simply cannot remove it. You can't replace it with 2.7 either. You can install 2.7 alongside it if you want (seems like you have). -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish => Greek (subprocess complain)
On 06/02/2013 11:12 AM, Νικόλαος Κούρας wrote: > Τη Κυριακή, 2 Ιουνίου 2013 8:05:32 μ.μ. UTC+3, ο χρήστης Chris Angelico > έγραψε: > >> A programmer chooses his own clients, and you are the Atherton Wing to >> my Inara Serra. > > You might want to explain this mystique call-name you inprovised for me? Maybe you could research it a bit. -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On 06/01/2013 01:51 AM, Νικόλαος Κούρας wrote: > Τη Σάββατο, 1 Ιουνίου 2013 9:18:26 π.μ. UTC+3, ο χρήστης Chris > Angelico έγραψε: > >> That would require that the repo have a 3.3.2 build in it. I don't >> know the Red Hat / CentOS policies there, but I know Debian stable >> wouldn't have anything so new - it takes time to test things. > > Is there a way to change to some repo that contain the latest python > 3.3.2 to yo yum it? Let me brutally blunt here, nick: have you googled for the answer or are you just expecting us to do all your research for you? I googled for this out of curiousity and found at least one third-party repo that did have Python 3.3.x in it for CentOS/RHEL 6.4. I'll give you a free hint about finding it: sometimes you have to add RHEL to the search term as well as CentOS, since CentOS is a free clone of RHEL. From now on, Νικόλαος, before asking a question like this on this list, please state what google search terms you used, what you found, and why the google searches did not turn up the information you seek. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish => Greek (subprocess complain)
On 06/02/2013 12:34 PM, Νικόλαος Κούρας wrote: > The whole subprocess fails when it has to deal with a greek lettered > filename. No it doesn't. subprocess is working correctly. It's the program subprocess is running that is erring out. subprocess is merely reporting to you that it erred out, just as it should. > I just dont get it... I didn't ask for metrites.py to open via > subprocess the greek filename, i just told metrites.py to call > files.py which in turn tries to open that greek filename. Seems to me, then it's clear how you should go about debugging this. Have to run each layer separately, and see where the error occurs. Start with files.py. that's what any of us would do if the code were ours. But we can't do the debugging for you. It's not possible! We don't have access to your code nor to your server environment. Nor is it appropriate for any of us who have no contractual relationship with you to have such access to your server. Good luck. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish => Greek (subprocess complain)
On 06/02/2013 11:22 PM, Νικόλαος Κούρας wrote: > Ok, this email is something of a recital of how I approached this. Excellent. You're making progress. Keep doing research, and learn how to debug your python programs. One thing I've done as a last resort when I just can't get good error reporting because of subprocess or something else, is to have my script open a file in /tmp and write messages to it as the program executes. Sometimes I write out what the standard input was so I know for doing a standalone run. There's your free hint for the day. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: The problem with "print"
On 06/02/2013 12:18 PM, Rick Johnson wrote: > On Sunday, June 2, 2013 12:49:02 PM UTC-5, Dan Sommers wrote: >> On Mon, 03 Jun 2013 03:20:52 +1000, Chris Angelico wrote: >>> On Mon, Jun 3, 2013 at 3:04 AM, Rick Johnson >> [...] Or use the logging module. It's easy to get going quickly >> (just call logging.basicConfig at startup time), and with a little >> care and feeding, you can control the output in more ways than can >> fit into the margin. Oh, yeah, I'm sure it introduces some >> overhead. So does everything else. > > I hate log files, at least during development or testing. I prefer to > debug on the command line or using my IDE. Log files are for release > time, not development. Except that it's not. Have you even looked at what the logging module is? It most certainly can log to stderr if you provide no logging handler to write to a file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On 06/03/2013 09:01 AM, [email protected] wrote: > Maybe you should tell us how you find out yours. Chris and others have told you how they go about solving their problems. Quite a few times. In fact repeating themselves even. I think we've run out of different ways to saying it now. It's a process of research, tracing execution, understanding code flow, beta-testing code on a local machine (not on a production server!). Why do you expect it to be any different? -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On 06/03/2013 04:13 PM, Carlos Nepomuceno wrote: > '/var/log/httpd' is the default place for the Red Hat and CentOS installation > of httpd. > > '/usr/local/apache/logs' is the default directory of the Apache httpd > installation. > > httpd has probably been upgraded by 'make install'. Oh wow. What a mess. I think Nick needs to read a good book on Red Hat EL system administration. Think he needs to start over with a fresh install of CentOS and only install software that comes from a repo using yum until he learns what he's doing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On 06/03/2013 05:33 PM, Carlos Nepomuceno wrote: > I did a httpd 'make install' on CentOS 6 and it worked fine. Needed a > few tweaks that I don't remember though. > > If you don't have any previous experience with Apache httpd settings > I wouldn't try that on a production server. Precisely. Given his experience levels, installing httpd from source is recipe for disaster. He's now going to have to track security flaw reports manually, try to figure out which ones apply to him, and keep his apache up to date. I can't think of anything he'd need in Apache that's not in the CentOS packages. I've sys-admined for years and I've never ever needed an Apache outside out of the repos. Sometimes I needed other things I had to build from source, but never apache. -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On 06/04/2013 01:39 AM, Νικόλαος Κούρας wrote: > Well, since you dough me here it is: Did you even bother to google it? If you did, you'd find that python-pip is available in a semi-official repository called EPEL. Just about every RHEL and CentOS install should have EPEL installed. Now it's pip for Python 2.6 of course. If you need python 3.3, there is a repo out there (third-party of course) that google can help you find. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish => Greek (subprocess complain)
On 06/04/2013 08:18 AM, Νικόλαος Κούρας wrote:
> No, brackets are all there. Just tried:
>
> # Compute a set of current fullpaths
> fullpaths = set()
> path = "/home/nikos/www/data/apps/"
>
> for root, dirs, files in os.walk(path):
> for fullpath in files:
> fullpaths.add( os.path.join(root, fullpath) )
> print (fullpath )
> print (fullpath.encode('iso-8859-7').decode('latin-1') )
This is wrong. You are converting unicode to iso-8859-7 bytes, then
trying to convert those bytes back to unicode by pretending they are
latin-1 bytes. Even if this worked it will generate garbage.
> What are these 'surrogate' things?
It means that when you tried to decode greek bytes using latin-1, there
were some invalid unicode letters created (which is expected, since the
bytes are not latin-1, they are iso-8859-7!).
If you want the browser to use a particular encoding scheme (utf-8),
then you have to print out an HTTP header before you start printing your
other HTML data:
print("Content-Type: text/html;charset=UTF-8\r\n")
print("\r\n)
print("html data goes here)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with "print"]
On 06/04/2013 05:21 PM, Rick Johnson wrote: > If you still feel that this idea is garbage, then, keep on writing > your sloppy code. My proposal is the best method to handle the > problems that arise with duck typed languages in a manner that is not > restrictive or laborious -- it's actually quite elegant. Like most of your proposals, this does not have anything to do with the python syntax itself. You just demonstrated code that does what you want. So use it then. Adopt it in your own code, encourage others to use it. No changes to Python are needed. If this technique proves its value, then it will be adopted. If not, it will die. Start using it in one of your major open source projects. > *school-bell-rings* It's one thing to patronize people as you try to do to D'Aprano (and yes I admit that most replies to your posts are often patronizing to you in return), but you do realize this infantile attempt to try to make yourself look smarter than others really reflects poorly on you? I for one feel badly for you on this count, or at least embarrassed. So just a suggestion... drop the school bell and teacher stuff (or at least share your qualifications with us). It's really tiring, though to be fair not quite as tiring as trying to help someone with an iron skull get a CGI script working. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish => Greek (subprocess complain)
On 06/04/2013 10:15 PM, Νικόλαος Κούρας wrote: > One of my Greek filenames is "Ευχή του Ιησού.mp3". Just a Greek > filename with spaces. Is there a problem when a filename contain both > english and greek letters? Isn't it still a unicode string? > > All i did in my CentOS was 'mv "Euxi tou Ihsou.mp3" "Ευχή του > Ιησού.mp3" > > and the displayed filename after 'ls -l' returned was: > > is -rw-r--r-- 1 nikos nikos 3511233 Jun 4 14:11 \305\365\367\336\ > \364\357\365\ \311\347\363\357\375.mp3 > > There is no way at all to check the charset used to store it in hdd? > It should be UTF-8, but it doesn't look like it. Is there some linxu > command or some python command that will print out the actual > encoding of '\305\365\367\336\ \364\357\365\ > \311\347\363\357\375.mp3' ? I can see that you are starting to understand things. I can't answer your question (don't know the answer), but you're correct about one thing. A filename is just a sequence of bytes. We'd hope it would be utf-8, but it could be anything. Even worse, it's not possible to tell from a byte stream what encoding it is unless we just try one and see what happens. Text editors, for example, have to either make a guess (utf-8 is a good one these days), or ask, or try to read from the first line of the file using ascii and see if there's a source code character set command to give it an idea. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with "print"]
On 06/05/2013 12:11 AM, Russ P. wrote: > But then, what would you expect of a language that allows you to > write > > x = 1 > x = "Hello" > > It's all loosey goosey -- which is fine for many applications but > certainly not for critical ones. This comment shows me that you don't understand the difference between names, objects, and variables. May sound like a minor quibble, but there're actually major differences between binding names to objects (which is what python does) and variables (which is what languages like C have). It's very clear Rick does not have an understanding of this either. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with "print"]
On 06/05/2013 05:52 PM, Russ P. wrote: > My comment shows you nothing about what I understand about names, > objects, and variables. Yes that probably is true. > You have chosen to question my understanding apparently because my > point bothered you but you don't have a good reply. Then you link me > with Rick for good measure. That's two ad hominems in three > sentences. Your statement didn't bother me. I just felt, perhaps erroneously, that such a comment needs clarification. We get into trouble in python when we get caught up in treating python names exactly like variables and blame it on the lack of static typing. In uni we looked at various means of dealing with the name covering/hiding issue including renaming or requiring that each binding be a unique name (meaning the second x = "hello word" statement would be a runtime error). Anyway, I got a bit distracted by your example of using the same name twice with different objects when the real issue that can cause pain is function call parameter expectation. My apologies for linking you to Rick. You're right that was an ad-hominem attack, though I didn't intend that! -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
On 06/08/2013 10:56 AM, Νικόλαος Κούρας wrote: > its very tedious to always triming everything for me and i know it is > for you to ead it assuc. Damn google groups, why is it behaving as > such? Dont the programmers know about it? Most of us on the list don't use google groups. A number of us use plain old e-mail to post to the list. If you set up folders and rules in your e-mail client (or labels and filter in Gmail), then messages can go into their own folder. > Any way what did you say and i havent understand you correctly? What > path do you want me to show to you? He means that you should configure apache to use the real path on your file system, not the symlink. IE if www is just a symlink to public_html, reconfigure apache to not use www at all and use public_html. That way you can avoid these kinds of errors. > What does this error means anyway? It means that Apache is unable to find your cgi script. It's turning the url into a file path, but it can't find the file path. Sometimes Apache is configured to not follow symlinks. It's confusing too because you have two apaches installed. The system default one and the one that comes with cPanel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-using copyrighted code
On 06/09/2013 11:18 AM, Mark Janssen wrote: >> I understand that I have to pick a license for my package. > > You actually do not. Attaching a legal document is purely a secondary > protection from those who would take away right already granted by US > copyright. You are correct, except that the OP has already stated he wishes to have his code distributed. Without granting a license, the code cannot be distributed beyond the people he personally gives the code too. PyPi cannot legally allow others to download it without a license. Here's how the GPL puts it, and of course this applies to any and all licenses, even proprietary ones: "However, nothing else [besides the License] grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying..." -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-using copyrighted code
On 06/09/2013 02:32 PM, Mark Janssen wrote: > PyPi. But if you are *publishing*, there's no court which can > protect your IP afterwards from redistribution, unless you > explicitly *restrict* it. I am not a lawyer, and I haven't read the copyright act in its entirety, nor have I studied all the case law surrounding copyright, but your statement is exactly backwards of anything I've ever read on US copyright. What relevant case law supports this view? It's a very interesting opinion. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-using copyrighted code
On 06/09/2013 08:30 PM, Mark Janssen wrote: >> Can you provide any citations for your interpretation? Besides "that's >> what the law should be", I mean. > > I don't think I even have to: the legal code you're citing above is > not very clear, consistent, or well-defined at all. As such, it shows > that this area remains an area that has yet to be worked out by all > parties involved. I would happily volunteer for any interested > parties to such a broken system. Alternatively, I've been working on > a real fix to IP protections in the form of a unified data model for > the internet and data ecosystem. Except that's now how law works in the US. All laws are unclear, inconsistent or ill-defined. Many laws even contradict existing laws. That's why there's a long history and tradition (for good or ill) of courts establishing case law to clarify and codify the implementation of law, and to resolve incompatibilities and consistencies. So while your views may be logical to you, and even common sense, unless case law backs you up, your opinions are irrelevant to the actual implementation of copyright law. As much as many of us are open source or even free software advocates, we do have to live within the copyright law currently, and use (or exploit) it to our benefit and to preserve our rights. Meaning if I as a developer produce code, and if I wish this code to be of use to others while still protecting my own rights under copyright law, I have to adopt a suitable distribution license. And if I use existing code that is already under license, I have to take that into consideration. It's not fair use. It's code license. That is why this issue does matter, and why the original poster asked his questions in the first place. -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On 06/11/2013 02:20 PM, Νικόλαος Κούρας wrote:
> [code]
> if not re.search( '=', name ) and not re.search( '=', month )
> and not re.search( '=', year ):
What do each of these functions return? When you print out
re.search('=', name) what happens?
When you're debugging you should print each of these out. Also make a
standalone program (NOT A CGI SCRIPT) for debugging. You can test
various inputs by simply going:
name = "My test name"
month = "Thirteenth"
year = "2013"
One thing I do is to make my code into functions and then at the bottom
of each script I have something like this:
if __name__ == "__main__":
# run some test code here
# or alternatively do the CGI stuff depending on what
# mode you're in.
You could even put in debugging flags (apologies to Rick who recently
raved against needing to resort to this sort of thing).
Consider this code:
-- do_something.py ---
debug = False
def do_something(name, month, year):
if debug:
print re.re.search( '=', name )
print not re.search( '=', month )
print not re.search( '=', year )
if not re.search( '=', name ) and not re.search( '=', month ) and
not re.search( '=', year ):
print "gonna do query"
# code follows
if __name__ == "__main__"
debug = True
do_something("bob", None, 2012)
do_something(None, None, None)
do_something("big", "Octember", 2067)
# other use cases here
-
Then in your cgi script itself, you just do this:
--- my_cgi_script.py ---
import do_something
# handle cgi stuff
# get name, month year
dosomething.dosomething(name, month, year)
Now to test your code you can just run the module directly with python,
and once you've got it working, the CGI will also work, since it pulls
in the same code.
If this concept is new to you, I strongly urge you to stop development
and read through a good python tutorial or get a good python book.
--
http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On 06/11/2013 10:49 PM, Michael Torrie wrote: > --- my_cgi_script.py --- > import do_something > > # handle cgi stuff > # get name, month year > dosomething.dosomething(name, month, year) Make that do_something.do_something -- http://mail.python.org/mailman/listinfo/python-list
Re: Eval of expr with 'or' and 'and' within
On 06/14/2013 03:50 AM, Nick the Gr33k wrote: > >>> print(name or month or year) > abcd > >>> print(name and month and year) > ijkl Interesting. I'd have thought a boolean expression would return True or False, not a string. Learn something new every day. -- http://mail.python.org/mailman/listinfo/python-list
Re: Eval of expr with 'or' and 'and' within
On 06/14/2013 10:49 AM, Steven D'Aprano wrote: > Correct. In Python, all boolean expressions are duck-typed: they aren't > restricted to True and False, but to any "true-ish" and "false-ish" > value, or as the Javascript people call them, truthy and falsey values. > > There are a couple of anomalies -- the timestamp representing midnight is > falsey, because it is implemented as a zero number of seconds; also > exhausted iterators and generators ought to be considered falsey, since > they are empty, but because they don't know they are empty until called, > they are actually treated as truthy. But otherwise, the model is very > clean. Good explanation! Definitely enlightened me. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On 06/15/2013 07:07 AM, Nick the Gr33k wrote:
> result = mylist (since its a no-emoty list)
>
> result.append('bar')
> result is mylist
>> True
>
> Never seen the last statement before. What does that mean?
> result is mylist
Yes. Surprisingling good question.
http://docs.python.org/3.3/reference/expressions.html#is
http://docs.python.org/3/reference/datamodel.html
One thing that you may find interesting is that what we often call
variables in Python, and which from your code's point of view look and
act like variables are in fact names. Whereas in C, assignment can be
thought of as copy (a = b in C means that b's value is copied to a), in
Python assignment is associating a name with an object. Thus a = b in
Python means that now the names a and b both are bound (reference to)
the same object. That's why the "is" operator is there, to help one
know if two names point to the same object.
I bring this up on the list from time to time because I find it really
interesting and intellectually appealing the way Python works. Hearkens
back to my class at uni on programming language theory.
--
http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On 06/15/2013 10:18 AM, Nick the Gr33k wrote: > a and b you say are names, which still are memory chunks Yes no matter how you look at it, a dictionary of names and objects is memory and "variables" in that sense. But at a higher level, we can consider the differences with how a language like C defines variables. > In both situations we still have 2 memory units holding values, so hows > that different? Perhaps one could think of python names as more like pointers or references in C. But python references are counted and garbage-collected (more like a C++ reference-counting pointer type). For example, a = 4 makes the name "a" be a reference to the object int(4), which will never ever change in its lifetime (indeed it wouldn't make sense for the integer 4 to change otherwise it wouldn't be a 4). Thus a = a + 1 creates a new object that represents the integer value of 4 + 1, and throws the old object away. >>> a = 5 >>> id(a) 2857664 >>> a = a + 1 >>> id (a) 2857680 >>> Note that the identity (object) of a has changed. If a were a variable in the same sense as C, the identity of a would not change. A mutable object like a list acts more like a variable in some ways: >>> b = [] >>> id(b) 3076765292 >>> b.append(3) >>> id(b) 3076765292 In many cases the distinction is little more than intellectual for all intents and purposes, though it some cases the idea is very powerful. But there a couple of cases where the difference between a variable and a name referencing an object does bite people in Python: http://effbot.org/zone/default-values.htm http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On 06/15/2013 11:30 AM, Nick the Gr33k wrote: > You are spamming my thread. No he's not. The subject is changed on this branch of the thread, so it's easy to see in any good e-mail reader that this sub-thread or branch is diverting. This is proper list etiquette. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/17/2013 05:34 AM, Simpleton wrote: > So is it safe to say that in Python a == &a ? (& stands for memory address) > > is the above correct? It might be partially equivalent inside the interpreter, but it's not something you should concern yourself with. And in general, no it's not safe to say, since Python is a reference-counted, garbage-collected object system and pointers in C certainly are not. > I say this because here you said that: Instead, there is a namespace, > which is anassociation between some name and some value: > > When you say that you mean that a is associated to some value as in > memory location or to that memory location's address? In python just think of assignment as making a name *be* an object. And if you assign one name to another name, that makes both names be the same object. When names are unbound (either they go out of scope or you manually unbind them), the objects they are bound to are garbage collected. Forget about the details of how the interpreter might doing at a low level. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/18/2013 03:51 AM, Νίκος wrote:
> Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
>> Names are *always* linked to objects, not to other names.
>>
>> a = []
>> b = a # Now a and b refer to the same list
>> a = {} # Now a refers to a dict, and b refers to the same list as before
>
> I see, thank you Steven.
>
> But since this is a fact how do you create complicated data structures
> that rely on various variables pointing one to another liek we did in
> C++(cannot recall their names) ?
>
As Steve said Python provides all manner of data structures and the
means to create data structures. Any data structure (trees, lists, etc)
can all be made easily in Python using Python's basic data structures,
if the built-in data structures are not sufficient. It turns out that
lists, hashes (dicts), and classes can pretty much do anything with
having to much about with C-style pointers and such.
Do yourself a favor and forget about the low-level stuff in Python for
now. You'll be more frustrated if you don't.
The real power and expressivity of Python comes from embracing the
abstractions that Python provides to your advantage. There's a certain
elegance and beauty that comes from such things, which I believe really
comes from the elegance and beauty of LISP, some of which manages to
shine forth in Python, despite its deficiencies. When I first learned
Python, I was impressed that some of the elegance that I remember from
Scheme (how to use lists as a basic type for example) was there, but in
a form that appealed to me.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/19/2013 11:16 PM, Michael Torrie wrote: > It turns out that lists, hashes (dicts), and classes can pretty much > do anything with having to much about with C-style pointers and > such. Oh wow. Parse error. should read, "pretty much do anything without having to muck about with C-style pointers and such." -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/19/2013 11:48 PM, Steven D'Aprano wrote: > On Wed, 19 Jun 2013 23:16:51 -0600, Michael Torrie wrote: > >> The real power and expressivity of Python comes from embracing the >> abstractions that Python provides to your advantage. There's a certain >> elegance and beauty that comes from such things, which I believe really >> comes from the elegance and beauty of LISP, some of which manages to >> shine forth in Python, despite its deficiencies. When I first learned >> Python, I was impressed that some of the elegance that I remember from >> Scheme (how to use lists as a basic type for example) was there, but in >> a form that appealed to me. > > > Well said! Glad you made sense of it... the bit about LISP and Scheme came out a wee bit muddled. In fact thinking about it, perhaps LISPers would say about Python what a bible passage says about having the form of Godliness but denying the power thereof! For example, Python's lambda functions, and Python's functional programming capabilities in general. But since the LISP never really got a form beyond S-expressions, leaving us with lots of parenthesis everywhere, Python wins much as the Hitchhiker's Guide to the Galaxy wins. -- http://mail.python.org/mailman/listinfo/python-list
Re: Default Value
On 06/21/2013 07:41 PM, Chris Angelico wrote: >> While we're at it, I would like to petition for a function >> terminates(f, args) that I can use to determine whether a function >> will terminate before I actually call it. > > Nice idea from a theoretical point of view, but practicality beats > purity, and most people know their functions will terminate (that's > what Ctrl-C is for). No, I want a function isbuggy(f) to find out > whether a function is, well, buggy. We could abolish all unit-testing > if we had that. That's awesome. I laughed out loud when I read Ian's comment, though it took me longer than I should have needed to notice your tongue firmly in your cheek as well. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python development tools
On 06/23/2013 02:40 PM, cutems93 wrote: > What else do I need? Also, which software is used in daily base? I > know version control software and bug tracking software are used > almost everyday by developers. Which software is used less often? Phew that's quite a list you have there. Are you coming from Windows development? I personally do all my development with vim, git, and a web browser for reference (or Python in a nutshell book). Dunno why things necessarily have to be complicated. > Also, I will use GUI interface for Python. What kind of widget > toolkits do you recommend? I know there are GTK+ and Qt. Yes I recommend a nice GUI toolkit. Pick one and try it out. -- http://mail.python.org/mailman/listinfo/python-list
Re: Making a pass form cgi => webpy framework
On 06/23/2013 07:44 PM, Νίκος wrote: > Why use mako's approach which requires 2 files(an html template and the > actual python script rendering the data) when i can have simple print > statements inside 1 files(my files.py script) ? > After all its only one html table i wish to display. Sooner or later your needs grow to the point where your single python CGI file is mixing so much html and python code that it becomes unwieldy. > And if we wanted to to compare an html template method to a web > framework solution? A web framework gives you database abstractions so you can easily target most SQL servers without changing code (MySQL, MS SQL, PostgreSQL, Oracle, etc), and they also provide frameworks for doing authentication and authorization. Authorization in particular becomes unwieldy quickly if you have to do it all in CGI. With a framework it's relatively easy to decorate a view with a wrapper that can only allow the view to be displayed if a web client has logged in with a particular set of permissions (stored in your user database of coures). > What are the benefits of one over the other? If you need to do user logins, a framework is going to become rather essential, in my opinion. At least if you need to support fine-grained permissions, which is what most enterprise web apps require (at least the ones I worked on). > I know you dont use the latter but this questios is for averybody that does. Personally I feel that a templating engine is essential for any web development, CGI or not. Mixing html and code leads to an unmaintainable mess. A framework is not essential, but often desired. If you don't use a framework, eventually you'll find yourself creating your own framework in essence, though often not nearly as robustly or as flexibly. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 05:44 AM, [email protected] wrote: > Alas, one reason it's a weak workaround is that it doesn't work - at least, > not how I wish it would: > > > $ cat ptrs > > x = 34 > > def p1 (a1): > > a1[0] += 12 > > p1 ([x]) > > print (x) > > $ python ptrs > 34 you'll have to use it more like this (and also changing your names to be a bit more sane): x = [ 34, ] def test_func( out ): out[0] += 12 test_func(x) print (x) -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 05:21 AM, [email protected] wrote: > Thank you. You reminded me of the (weak) workaround of using arrays > and confirmed my suspicion that I although I can read the variable, I > won't be able to write to it. I still don't understand why not, > though... The real problem here is that you don't understand how python variables work. And in fact, python does not have variables. It has names that bind to objects. If you assign a value to a name, you're not overwriting a variable, you're rebinding a name to a new object in the default scope (unless it's declared global, or nonlocal in python 3, the latter I assume uses the same scope in which it was first declared, but I could be wrong). Since the name is in the local scope, the original name in the caller's scope is still bound to its original object. Furthermore, most primitive objects in python (strings, ints, etc) are immutable, which means they can *never change*. "Writing" to a variable simply dereferences the old object (which may still be referenced in the caller's scope) and creates a new object and binds it to the name. A list is mutable, which is why it's one solution to emulate a variable. > As for python 3 ... "nonlocal"? I see I'm not alone in picking > obnoxious names ... nonlocal at least has meaning. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 11:02 AM, Antoon Pardon wrote: > Op 29-06-13 16:02, Michael Torrie schreef: >> >> The real problem here is that you don't understand how python variables >> work. And in fact, python does not have variables. It has names that >> bind to objects. > > I don't understand why members of this list keep saying this. Sure the > variables in python behave differently than those in C and algol But > they behave similarly as those in smalltalk and lisp and I haven't seen > anyone claim that smalltalk and lisp don't have variables. > > We might as well say that C doesn't have variables, it has names > pointing to memory locations or value containers or something > like that. Sure but a memory location that contains say an int in C *is* a variable, with or without a name. You can change the int stored in that memory address at will, as part of your normal course. Python's basic data types are immutable. At best we could say they are read-only variables. So no, saying Python doesn't have variables is not the same as saying C doesn't have variables but only memory locations. They are different concepts entirely, though on the surface they look similar. > > AFAICS there is no reason why "variable" wouldn't be appropiate > for python names as opposed to C names. Sure I see your point, but then again, calling them variables is what led to the OP's issue in the first place. So yes they look like variables, and for the most part act like them, except when they don't. Hence the confusion and why I bring up the difference between python's name binding mechanism and how a variable works. It's exactly the concept that was tripping up the OP. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 07:56 AM, Michael Torrie wrote: > x = [ 34, ] > > def test_func( out ): > out[0] += 12 > > test_func(x) > > print (x) Well, actually print (x[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 12:37 PM, [email protected] wrote: > :) Thank you guys for saying what I was biting my tongue about > (thanks everybody for the help, BTW!). Sometimes it's best to state the actual problem you're trying to solve and see if there's a pythonic solution that fits it rather than to hack a solution transliterated from C. I'm curious as to if you did get something working and what you ended up with. > This "python-think" stuff was starting to get on my nerves - but then > it occurred to me that - although having many powerful features - it > has so many weird restrictions that it requires a special way of > thinking and problem solving. Interesting point of view. "Pythonic" ways of programming is in my mind the number one appeal of Python. It's quite clean yet practical. Has enough of the intellectual purity of LISP, Smalltalk, and functional languages to be appealing, yet the practicality of a traditional procedural language. In any language, though you have to grasp the data model. Usually the criticisms of Python come from not a failure to do this, either because it's hard to learn at first, or because people dislike learning something different than what they are used to. A while back we had a fairly pleasant gentleman come on the list from a C# background. His frustrations with Python stemmed from wanting it to be like C#, which of course it isn't. He did not have much success and I'm afraid was left with a sour taste of Python, which of course had nothing to do with the language itself. Python certainly has inconsistencies and there are newbie behavioral gotchas. > I have to work with perl's object-orientation stuff again for awhile, > in order to see if either has an advantage. Your original post mentioned nothing about object-orientation, so I have no idea how you intend to use OO design, but I think you'll find Python's model fairly workable and consistent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 12:51 PM, Steven D'Aprano wrote:
> You are absolutely correct in principle. But in practice, there are ten
> bazillion C, Pascal, COBOL, and BASIC programmers who understand the word
> "variable" to mean a named memory location, for every Smalltalk or Lisp
> programmer who understands a "variable" as a name binding. So it's pure
> weight of numbers thing.
>
> The average Lisp programmer will be completely aware that "variable" can
> mean various things, and take care to determine what the word means in
> Python. She will immediately grok what we mean, even if she thinks that
> the "no variables" part is just an affectation ("Heh, those wacky Python
> dudes think they don't have variables!") but at least she'll understand
> the name binding part.
>
> On the other hand, the average C programmer is barely aware that there
> are other languages at all, let alone that some of them differ from C in
> semantics as well as syntax. So by emphasising the differences ("Python
> has no variables? It has name bindings?") we increase the likelihood that
> he'll learn the differences in semantics as well as syntax.
>
> So, in a very practical sense, "Python has no variables, it has name
> bindings" is completely wrong except in the sense that really matters:
> Python's variables don't behave identically to C variables.
Very good points. Thank you. Good tips for how to better explain
things next time it comes up. I'll avoid simply saying "Python has no
variables."
--
http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 01:19 PM, Steven D'Aprano wrote: > Python's basic data types are not necessarily immutable. Lists and dicts > are not immutable. Being a high-level language, the idea of "primitives" > like int, double, float, etc from C doesn't really apply. A Python dict > is not made up from Python ints. Both int and dict are equally "basic". Indeed. Sorry for not being more clear. I was referring primarily to numeric objects and strings. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 01:20 PM, [email protected] wrote: > exactly that. Without wanting to analyze it in too much depth now, I > would want a local keyword to allow me to know I was protecting my > variables, and a way to specify other scopes, without so much implied > scoping in non-intuitive ways... The technical thing you are trying to accomplish, is, as far as I know, not easily doable in Python, except if you use a mutable object like a list. > > Now everybody is gonna tell me how wrong I am, but you asked what I > want, and that's what keeps aggrevating me with python. I presume you're answering the question of "what is it you're trying to do." Can't be sure. But chances are good. Far be it from me to tell you how wrong you are. I'm still not even sure what you're trying to do ultimately. -- http://mail.python.org/mailman/listinfo/python-list
Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte
On 07/04/2013 02:25 PM, Ferrous Cranus wrote: > try: > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > except: > host = "Reverse DNS Failed" > > Is there a way to write the above so i cna print the error return when > it fails? > Do you know what IP address causes the failure? If so write a little python program that does the socket.gethostbyaddr and run it on the command line! Debugging through the CGI interface sucks. Have you been writing python tests that you can run on the command line during your development these last weeks? -- http://mail.python.org/mailman/listinfo/python-list
Re: Stack Overflow moderator “animuson”
On 07/10/2013 06:22 AM, Mats Peterson wrote: > You're showing by these examples what regular expressions mean to you. Chris is showing no such thing. And you are simply trolling. What do you want us to do, fall down and worship you and admit that Python is a horrible language and we should all use Perl? What is your point? Are you looking for an admission of Python's slowness compared to Perl? If so, then yes it's slower. For what I need it for, it does not matter. Maybe you could write a better regex engine for python. Then we'd have the best of both worlds. -- http://mail.python.org/mailman/listinfo/python-list
Re: Stack Overflow bans Mats Peterson (was Re: Stack Overflow moderator “animuson”)
On 07/10/2013 06:06 AM, Mats Peterson wrote: > I haven't provided a "real-world" example, since I expect you Python > Einsteins to be able do an A/B test between Python and Perl yourselves > (provided you know Perl, of course, which I'm afraid is not always the > case). And why would I use any "custom" version of Python, when I don't > have to do that with Perl? Oh wow. You really do sound like Ranting Rick. Always wanting someone else to do the work and carry the burden of proof. Since you don't use Python, don't like Python, and don't promote Python, why are you here on this list? Are you evangelizing Perl? Apologies to the list; I hope I'm done. -- http://mail.python.org/mailman/listinfo/python-list
Re: Stack Overflow moderator “animuson”
On 07/10/2013 02:43 AM, Mats Peterson wrote: > I fear you don’t even know what a regular expression is. Then this will > of course not affect you. Hmm, and your stack exchange posts had a similar tone, hmm? I for one have never ready any of your posts on this forum before, so it looks like you've come here solely to troll. Perhaps your time would be better spent contributing a faster regex engine to the Python standard library. -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/12/2013 09:59 AM, Joshua Landau wrote: > If you're interested, the basic of it is that strings now use a > variable number of bytes to encode their values depending on whether > values outside of the ASCII range and some other range are used, as an > optimisation. Variable number of bytes is a problematic way to saying it. UTF-8 is a variable-number-of-bytes encoding scheme where each character can be 1, 2, 4, or more bytes, depending on the unicode character. As you can imagine this sort of encoding scheme would be very slow to do slicing with (looking up a character at a certain position). Python uses fixed-width encoding schemes, so they preserve the O(n) lookup speeds, but python will use 1, 2, or 4 bytes per every character in the string, depending on what is needed. Just in case the OP might have misunderstood what you are saying. jmf sees the case where a string is promoted from one width to another, and thinks that the brief slowdown in string operations to accomplish this is a problem. In reality I have never seen anyone use the types of string operations his pseudo benchmarks use, and in general Python 3's string behavior is pretty fast. And apparently much more correct than if jmf's ideas of unicode were implemented. -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On 07/13/2013 12:23 PM, Νικόλας wrote: > Do you know a way of implementing anyone of these methods to a script? Yes. Modern browsers all support a location API in the browser for javascript. See this: http://diveintohtml5.info/geolocation.html -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On 07/12/2013 10:32 AM, Νικόλας wrote: > So, my question now is, if there is some way we can get an accurate Geo > City database. As has been said pretty much by every other poster, there is no way to do get an accurate location database. Period. The databases that do exist were built by hand, and also guessed at based on routing information. The best you can really do is region, or country, and even that fails sometimes. If you want to know a visitor's city you should ask them using the new browser location apis available to javascript. http://diveintohtml5.info/geolocation.html Since IPs can be dynamic, sometimes even assigned across a region, there's no way to accurately map ip addresses to a city with the reliability that you seem to want. Google is pretty accurate because they've spent a lot of time building up their own database, and also convincing users to reveal their locations to them. Unless you do the same thing, you have to just get by with what others have provided for you. -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On 07/15/2013 06:34 PM, Dennis Lee Bieber wrote: >> I have no idea how to implement the solution you proposed. >> These are nice ideas we need to have a way of implement them within a >> script. >> >> I have no way of grasping a map of cell towers of a map of wi-fi hotspots. >> > You don't... The phone company knows where their towers are, THEY do > the triangulation based on signal strength from cell phones on their > network, and they provide that position to the phone. The phone can then > use that data to respond to applications running ON the phone that request > location information using the phone's OS API (which is different for an > Android phone vs Blackberry vs Apple). I've posted a link to detailed information on this no less than three times, yet Nikos has not read any of it, sadly. -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter redraw rates
On 07/17/2013 05:08 AM, [email protected] wrote: > Ok. Well, what I'm currently doing, based on advice from this thread, > is to create a new thread that handles the downloading, as well as > updating a variable for text display on the GUI, and in the main > thread, just after the thread is created, a while loop that updates > the GUI while the thread is running. Not sure what you mean by "while loop." In an event-driven paradigm, one technique would be to set a timeout event that fires every so many ms. Then in the event callback, you update the widget according to the new value of the variable. At least this is how i'd do it in Qt or GTK. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why on CentOS, python consumes too much memory ?
On 07/18/2013 03:13 AM, William Bai wrote: > I found that it was caused by not by python but by > /usr/lib/locale/locale-archive, the same problem as that described > in http://illiterat.livejournal.com/4615.html. Too funny. So in other words there isn't a problem at all. What you thought was RAM usage was really just a memory-mapped file. That's why Antoine said that using VSS to determine memory usage is not valid at all in determining memory footprint. VSS shows all kinds of things from shared libraries to locale archives that have zero impact on RAM usage. Every app will show at least the size of glibc in its VSS number. What is "too much memory" anyway? What do you mean by "consume too much memory?" Now if your script has a resource leak and is long-running, then that's a problem, but the solution is to fix your resource leak, not have the OS kill your app when it exceeds the RLIMIT. -- http://mail.python.org/mailman/listinfo/python-list
Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)
On 07/17/2013 11:39 PM, Eric S. Johansson wrote: > Not discourage you but this is a "been there, done that" kind of project. > You could learn more from reading somebody else is code. What hasn't been > done, and this would be very cool, is a chat program that works > peer-to-peer with no central server. To do this, you would probably need > to know about distributed hash tables and methods of piercing address > translation firewalls (think UDP). University CS curricula across the world would disagree with your assessment of the usefulness of "been there, done that." Indeed that's how you learn by doing simple things that have been done many times before, and discovering the magic of programming and software design. My uni's CS undergrad degree consists of dozens of contrived projects that have been done before. Web crawlers, compilers, expert systems, chat systems, word counters, etc. And that's the same way with all fields of endeavor. Indeed it'd be silly to tell an enthused hobby builder that building a shed is pointless as it's been done before. The shed itself, which would arguably be useful, is beside the point. -- http://mail.python.org/mailman/listinfo/python-list
Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)
On 07/18/2013 12:19 PM, Owen Marshall wrote: > Huh - I (foolishly) didn't realize gmane actually had NNTP, I've always > used it to search mailing lists. If the list dumped to usenet (much like > c.l.python) I'd post through sunsite.dk, which is a very nice usenet > provider. But that still meant several annoying mailing list > subscriptions. > > ... man, I'm really glad I read your post :-) I'm a bit confused. This list *is* c.l.python (I happen to read via e-mail through the mailing list). So you can reach it from sunsite.dk can you not? -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I make this piece of code even faster?
On 07/21/2013 04:19 AM, [email protected] wrote: > Thank's for all the replies! I've tried some of the imporovements you > suggested (using math.exp() and sum() or math.fsum()). > None of that made the code faster, because they are functions you are calling > lots of times, and function calling is quite time expensive (same as x**(1/2) > is faster than math.sqrt(x)). > > I'm going to try to convert tu numpy now (I have no idea how to do it at the > moment), thank's again to everyone. Perhaps you'd have better results if you'd post a runnable piece of code. Otherwise we're just guessing since no one has the ability to actually run your code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/21/2013 10:19 AM, Gilles wrote: > So, does someone know of a good, SMTP server just to send e-mails? What you're looking for is not an SMTP server but a Mail Transfer Agent, called an MTA. Pretty much all distros ship with an MTA by default, even if the SMTP server part of it isn't installed or running. And often the MTA is, for compatibility reasons, /usr/sbin/sendmail. http://stackoverflow.com/questions/73781/sending-mail-via-sendmail-from-python I'm sure there are MTA's implemented in python. Now that you know what they are called (not SMTP servers!) you can search for them. Dennis is correct, though, that most ISPs do block outbound port 25 connections for security and spam reasons, and require you to use their SMTP server, which precludes the use of the local MTA. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/21/2013 02:34 PM, Gilles wrote: > Thanks for the infos. Ideally, I was looking for a simple Windows app > as MTA, but a Python script is OK. The Sendmail MTA has been ported to many platforms including windows. But... > I'm not sure my ISP blocks outbound port 25 connections. I'll > experiment with a small Linux box. Having spent a long time managing e-mail servers, everything Ivan said in his reply is true as well. I had forgotten a lot of that since I haven't been running my own mail server (MTA or server part) in a while. I've sold my soul to Google for e-mail now with Google Apps for my domain. > I wist they would use a smarter SPAM filter that wouldn't flag > perfectly legit-looking outgoing e-mails. But then how would it know that legit-looking e-mails aren't in fact SPAM? E-mail is starting to be an almost intractable problem. No wonder the younger generations are just abandoning it entirely in favor of centralized, cathedral-style messaging systems such as facebook. -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?
On 07/21/2013 05:20 AM, Chris “Kwpolska” Warrick wrote: > On Sun, Jul 21, 2013 at 1:14 PM, Dave Cook wrote: >> On 2013-07-20, Aseem Bansal wrote: >> >>> Do I need to use QtCreator with PySide if I want drag-and-drop >>> feature for GUI development? >> >> No, you just need the layout part of QtCreator, called QtDesigner, and >> any decent Python editor or IDE (e.g. Idle): > > …and one more thing: pyside-uic, for transforming the .ui files into > (ugly) .py files. It seems to be in /PythonXY/Scripts according to > Stack Overflow if you have PySide installed. I don't think you want to be converting ui files into python classes. Just use the PySide Qt api for loading them at runtime. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/22/2013 06:51 AM, Chris Angelico wrote: >> Thanks for the tip. I didn't know about SPF >> http://en.wikipedia.org/wiki/Sender_Policy_Framework > > It's a great way of detecting legit vs forged mail. If anyone tries to > send mail purporting to be from [email protected] and the receiving > mail server is checking SPF records, it'll be rejected after one cheap > DNS lookup. It's a simple and cacheable way to ask the owning server, > "Is this guy allowed to send mail for you?". (The 192.168 block in my > SPF record above is permitted to allow some intranet conveniences; > omit it unless you need it.) Yes setting SPF records will help your mail be accepted by other servers, but I disagree with your appeal to make mail server SPF handling as strict as your server does. SPF has problems in a number of situations which could cause legitimate mail to be rejected. In my last job I could only use SPF as one spam factor, not as a basis for rejection. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/22/2013 06:19 AM, Gilles wrote: > On Sun, 21 Jul 2013 21:01:09 + (UTC), Grant Edwards > wrote: >> Unless you've got a static IP address, a domain name, and a valid MX >> record that will match up when they do a reverse DNS lookup, it's >> pretty unlikely that you're going to have much luck running an SMTP >> server. Most other SMTP servers are probably going to ignore or >> reject your attempts to transfer mail from your own SMTP server. > > Incidently, how do ISP MTAs find whether the remote MTA is legit or > running on some regular user's computer? > > 1. Query Reverse DNS for IP > 2. Find domain > 3. Query DNS for MX > 4. ? My mail server did a number of things: 1. ensure IP address of sending server has a reverse name (domain didn't particularly matter) 2. ensure the HELO address in SMTP matches IP address of sending server 3. check sender IP address against spam blacklists, which includes netblocks of home ISPs, some entire countries, flagged subnets 4. greylist sender IP if the recipient requested it. First connection always fails with a nonfatal server error, next connection must wait at least 5 minutes. If a reconnection happened too quickly, the IP was temporarily black listed. After success, IP address is whitelisted for a time. A commandline MTA will not be able to get through greylisting; only a mail server with queuing could. Spambots tend to give up on the first error, even now. Cheaper targets I guess. 5. spamassassin checked SPF (DNS) and domainkeys (message itself) and weighted the spam factor accordingly I think there were other basic rules that sendmail applied to the sender, but I can't remember all of what they are. This is well and truly off topic now for the python list, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/22/2013 06:11 AM, Gilles wrote: > On Sun, 21 Jul 2013 18:28:27 -0600, Michael Torrie > wrote: >> The Sendmail MTA has been ported to many platforms including windows. >> But... > > Thanks for the tip. Since I couldn't find a good, basic, native > Windows app, I was indeed about to look at eg. Exim + Cygwin, and > resort to a Linux appliance if none footed the bill. Where did you look? Here's one I found. It's not the real sendmail program, but it implements the interface which is all you need: http://glob.com.au/sendmail/ I just googled for sendmail win32 -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/22/2013 08:15 AM, Chris Angelico wrote: > If legit mail is rejected for failing an SPF check, it's the sending > admin's problem, not yours. You should never have problems with it if > it's set up correctly. And since rejected mail gets reported to the > transmitting MTA, you don't need to drop it in a spambox or anything. > It's not spam, it's simply invalid mail (equivalent to something sent > to a dud address). Sure. Tell that to the people you work for who depend on e-mail. When I was a sysadmin (quite recently), I'd have gotten fired for enforcing such an arbitrary policy. Indeed when mail wasn't coming through that someone in the organization was expecting and wanting, regardless of SPF, it was indeed *my* problem and my job was on the line. BOFH attitudes simply aren't going to change that reality. SPF is just one more of the many things that are contributing overall to absolutely breaking and demise of SMTP. I'm afraid when it does finally cease to work, it's going to be replaced with less open, centrally-controlled messaging systems like facebook. Which is unfortunate. -- http://mail.python.org/mailman/listinfo/python-list
[OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/23/2013 03:30 AM, Chris Angelico wrote: > On Tue, Jul 23, 2013 at 7:19 PM, Chris Angelico wrote: >> Ah, there's a solution to this one. You simply use your own >> envelope-from address; SPF shouldn't be being checked for the From: >> header. > > There's an example, by the way, of this exact technique right here - > [email protected] sends mail to me with an envelope-from of > "[email protected]" - which passes SPF, > since python.org has a TXT record designating the sending IP as one of > theirs. It doesn't matter that invalid.invalid (your supposed domain) > doesn't have an SPF record, nor would it be a problem if it had one > that said "v=spf1 -all", because that domain wasn't checked. Mailing > lists are doing the same sort of forwarding that you're doing. This is good and all, and I think I will modify my local postfix mail server I use for personal stuff, just for correctness' sake. I hadn't spent much time studying SPF in depth before, but after reading your comments (which were insightful) I'm now more convinced that SPF is worthless than ever, at least as a spam prevention mechanism. Spammers can use throwaway domains that publish very non-strict SPF records, and spam to their hearts content with random forged from addresses and SPF checks pass. The only way around that is to enforce SPF on the From: header in the e-mail itself, which we all agree is broken. I've been reading this: http://www.openspf.org/FAQ/SPF_is_not_about_spam Not very encouraging. When the other expensive options for going after spammers who have valid SPF records, they propose domain blacklists as a solution. -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/24/2013 07:40 AM, [email protected] wrote: > Sorry, you are not understanding Unicode. What is a Unicode > Transformation Format (UTF), what is the goal of a UTF and > why it is important for an implementation to work with a UTF. Really? Enlighten me. Personally, I would never use UTF as a representation *in memory* for a unicode string if it were up to me. Why? Because UTF characters are not uniform in byte width so accessing positions within the string is terribly slow and has to always be done by starting at the beginning of the string. That's at minimum O(n) compared to FSR's O(1). Surely you understand this. Do you dispute this fact? UTF is a great choice for interchange, though, and indeed that's what it was designed for. Are you calling for UTF to be adopted as the internal, in-memory representation of unicode? Or would you simply settle for UCS-4? Please be clear here. What are you saying? > Short example. Writing an editor with something like the > FSR is simply impossible (properly). How? FSR is just an implementation detail. It could be UCS-4 and it would also work. -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/24/2013 08:34 AM, Chris Angelico wrote: > Frankly, Python's strings are a *terrible* internal representation > for an editor widget - not because of PEP 393, but simply because > they are immutable, and every keypress would result in a rebuilding > of the string. On the flip side, I could quite plausibly imagine > using a list of strings; whenever text gets inserted, the string gets > split at that point, and a new string created for the insert (which > also means that an Undo operation simply removes one entire string). > In this usage, the FSR is beneficial, as it's possible to have > different strings at different widths. Very good point. Seems like this is exactly what is tripping up jmf in general. His pseudo benchmarks are bogus for this exact reason. No one uses python strings in this fashion. Editors certainly would not. But then again his argument in the past does not mention editors. But it makes me wonder if jmf is using python strings appropriately, or even realizes they are immutable. > But mainly, I'm just wondering how many people here have any basis > from which to argue the point he's trying to make. I doubt most of > us have (a) implemented an editor widget, or (b) tested multiple > different internal representations to learn the true pros and cons > of each. Maybe, but simply thinking logically, FSR and UCS-4 are equivalent in pros and cons, and the cons of using UCS-2 (the old narrow builds) are well known. UCS-2 simply cannot represent all of unicode correctly. This is in the PEP of course. His most recent argument that Python should use UTF as a representation is very strange to be honest. The cons of UTF are apparent and widely known. The main con is that UTF strings are O(n) for indexing a position within the string. -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/24/2013 04:19 PM, Chris Angelico wrote: > I'm referring here to objections like jmf's, and also to threads like this: > > http://mozilla.6506.n7.nabble.com/Flexible-String-Representation-full-Unicode-for-ES6-td267585.html > > According to the ECMAScript people, UTF-16 and exposing surrogates to > the application is a critical feature to be maintained. I disagree. > But it's not my language, so I'm stuck with it. (I ended up writing a > little wrapper function in C that detects unpaired surrogates, but > that still doesn't deal with the possibility that character indexing > can create a new character that was never there to start with.) This is starting to drift off topic here now, but after reading your comments on that post, and others objections, I don't fully understand why making strings simply "unicode" in javascript breaks compatibility with older scripts. What operations are performed on strings that making unicode an abstract type would break? Is it just in the input and output of text that must be decoded and encode? Why should a script care about the internal representation of unicode strings? Is it because the incorrect behavior of UTF-16 and the exposed surrogates (and subsequent incorrect indexing) are actually depended on by some scripts? -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/25/2013 01:07 PM, [email protected] wrote: > Let start with a simple string \textemdash or \texttendash > sys.getsizeof('–') > 40 sys.getsizeof('a') > 26 That's meaningless. You're comparing the overhead of a string object itself (a one-time cost anyway), not the overhead of storing the actual characters. This is the only meaningful comparison: sys.getsizeof('––') - sys.getsizeof('–') sys.getsizeof('aa') - sys.getsizeof('a') Actually I'm not even sure what your point is after all this time of railing against FSR. You have said in the past that Python penalizes users of character sets that require wider byte encodings, but what would you have us do? use 4-byte characters and penalize everyone equally? Use 2-byte characters that incorrectly expose surrogate pairs for some characters? Use UTF-8 in memory and do O(n) indexing? Are your programs (actual programs, not contrived benchmarks) actually slower because of FSR? Is FSR incorrect? If so, according to what part of the unicode standard? I'm not trying to troll, or feed the troll. I'm actually curious. I think perhaps you feel that many of us who don't use unicode often don't understand unicode because some of us don't understand you. If so, I'm not sure that's actually true. -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/25/2013 11:18 AM, Steven D'Aprano wrote: > JMF has explained that it is impossible, impossible I say!, to write an > editor using a flexible string representation. Since Emacs uses such a > flexible string representation, Emacs is impossible, and therefore Emacs > doesn't exist. Now I'm even more confused. He once pointed to Go as an example of how unicode should be done in a language. yet Go uses UTF-8 I think. But I don't think UTF-8 is what JMF refers to as "flexible string representation." FSR does use 1,2 or 4 bytes per character, but each character in the string uses the same width. That's different from UTF-8 or UTF-16, which is variable width per character. -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/26/2013 07:21 AM, [email protected] wrote: sys.getsizeof('––') - sys.getsizeof('–') > > I have already explained / commented this. Maybe it got lost in translation, but I don't understand your point with that. > Hint: To understand Unicode (and every coding scheme), you should > understand "utf". The how and the *why*. Hmm, so if python used utf-8 internally to represent unicode strings would not that punish *all* users (not just non-ascii users) since searching a string for a certain character position requires an O(n) operation? UTF-32 I could see (and indeed that's essentially what FSR uses when necessary does it not?), but not utf-8 or utf-16. -- http://mail.python.org/mailman/listinfo/python-list
FSR and unicode compliance - was Re: RE Module Performance
On 07/27/2013 12:21 PM, [email protected] wrote: > Good point. FSR, nice tool for those who wish to teach > Unicode. It is not every day, one has such an opportunity. I had a long e-mail composed, but decided to chop it down, but still too long. so I ditched a lot of the context, which jmf also seems to do. Apologies. 1. FSR *is* UTF-32 so it is as unicode compliant as UTF-32, since UTF-32 is an official encoding. FSR only differs from UTF-32 in that the padding zeros are stripped off such that it is stored in the most compact form that can handle all the characters in string, which is always known at string creation time. Now you can argue many things, but to say FSR is not unicode compliant is quite a stretch! What unicode entities or characters cannot be stored in strings using FSR? What sequences of bytes in FSR result in invalid Unicode entities? 2. strings in Python *never change*. They are immutable. The + operator always copies strings character by character into a new string object, even if Python had used UTF-8 internally. If you're doing a lot of string concatenations, perhaps you're using the wrong data type. A byte buffer might be better for you, where you can stuff utf-8 sequences into it to your heart's content. 3. UTF-8 and UTF-16 encodings, being variable width encodings, mean that slicing a string would be very very slow, and that's unacceptable for the use cases of python strings. I'm assuming you understand big O notation, as you talk of experience in many languages over the years. FSR and UTF-32 both are O(1) for slicing and lookups. UTF-8, 16 and any variable-width encoding are always O(n). A lot slower! 4. Unicode is, well, unicode. You seem to hop all over the place from talking about code points to bytes to bits, using them all interchangeably. And now you seem to be claiming that a particular byte encoding standard is by definition unicode (UTF-8). Or at least that's how it sounds. And also claim FSR is not compliant with unicode standards, which appears to me to be completely false. Is my understanding of these things wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/30/2013 12:19 PM, Antoon Pardon wrote: > So? Why are you making this a point of discussion? I was not aware that > the pro and cons of various editor buffer implemantations was relevant > to the point I was trying to make. I for one found it very interesting. In fact this thread caused me to wonder how one actually does create an efficient editor. Off the original topic true, but still very interesting. -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/30/2013 01:09 PM, [email protected] wrote: > Matable, immutable, copyint + xxx, bufferint, O(n) > Yes, but conceptualy the reencoding happen sometime, somewhere. > The internal "ucs-2" will never automagically be transformed > into "ucs-4" (eg). So what major python project are you working on where you've found FSR in general to be a problem? Maybe we can help you work out a more appropriate data structure and algorithm to use. But if you're not developing something, and not developing in Python, perhaps you should withdraw and let us use our horrible FSR in peace, because it doesn't seem to bother the vast majority of python programmers, and does not bother some large python projects out there. In fact I think most of us welcome integrated, correct, full unicode. -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/31/2013 01:23 AM, Antoon Pardon wrote: > Op 31-07-13 05:30, Michael Torrie schreef: >> On 07/30/2013 12:19 PM, Antoon Pardon wrote: >>> So? Why are you making this a point of discussion? I was not aware that >>> the pro and cons of various editor buffer implemantations was relevant >>> to the point I was trying to make. >> >> I for one found it very interesting. In fact this thread caused me to >> wonder how one actually does create an efficient editor. Off the >> original topic true, but still very interesting. >> > > Yes, it can be interesting. But I really think if that is what you want > to discuss, it deserves its own subject thread. Subject lines can and should be changed to reflect the ebbs and flows of the discussion. In fact this thread's subject should have been changed a long time ago since the original topic was RE module performance! -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/31/2013 02:32 AM, [email protected] wrote: > Unicode/utf* Why do you keep using the terms "utf" and "Unicode" interchangeably? -- http://mail.python.org/mailman/listinfo/python-list
Re: Help On Paramiko
On 06/19/2012 12:28 AM, [email protected] wrote: > Howdy All, > > I am trying to use paramiko to automate logging in to remote unix machines > and executing some commands there. > When I normally do ssh from my linux machine (with Python 2.6) to this > machine a different '>' prompt comes. It's a device specific custom prompt. > After I run 'enable' command here, a new prompt opens up. '#' which is also > custom prompt. > Then I need to run 'configure terminal' there. And then some more device > specific commands. I think you want an abstraction layer like fabric, or the old and venerable pexpect. Makes this kind of interaction a lot easier. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Qt4 Designer
On 07/13/2012 03:12 PM, Jean Dubois wrote: > Thanks for the extra docu references In this day and age, I think compiling ui files to code is probably on the way out. Instead you should consider using the ui files directly in your code. This has the advantage of letting you change the gui somewhat without having to recompile all the time. Here is are some links that gives one way of loading and parsing the ui file directly: http://www.riverbankcomputing.com/pipermail/pyqt/2007-April/015902.html http://bitesofcode.blogspot.ca/2011/10/comparison-of-loading-techniques.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Qt4 Designer
On 07/14/2012 11:13 AM, rusi wrote: > I looked at the second link and find code like this: > > app = None if ( not app ): app = QtGui.QApplication([]) > > Maybe I'm dense but whats that if doing there? > > Frankly I seem to be a bit jinxed with gui stuff. A few days ago > someone was singing the praises of some new themed tk stuff. I could > not get the first two lines -- the imports -- to work and then gave > up Since you haven't had any experience with gui development then probably loading ui files isn't the right place to start. First principles (creating gui widgets from scratch) would be it. In any case, the line in question is quite simple. It creates a QApplication object, which is basically the engine that drives all Qt applications. Once you call .run() on it, it takes over and handles all the mouse events and such for you. In fact you do not have any control over the program's execution from this point on, other than to define event call-back methods or functions that are called by the widgets when things happen, like mouse clicks. All gui toolkits operate this way. You set up the widgets, then you run the main engine or main event loop and control never returns to your main program until something triggers the end (like closing a window or the quit menu item is pressed). Probably a complete working example is what you need to see, that is documented. I primarily work with Gtk, but I'll whip up a Qt one tomorrow if I can. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Qt4 Designer
On 07/15/2012 01:58 AM, Vincent Vande Vyvre wrote: > Rusi is not the op, and his question is about these lines > > app = None > if ( not app ): Yeah that's a no-op. The original author of that code is clearly confused there. > > not this one > > app = QtGui.QApplication([]) > > which should be written like this > > app = QtGui.QApplication(sys.argv) Yeah. The QApplication not only is the main engine, but it also parses the command-line for certain flags that influence Qt's behavior, similar to gtk's main function that also parses command-line flags (specific to gtk's operation). -- http://mail.python.org/mailman/listinfo/python-list
Re: New internal string format in 3.3
On 08/19/2012 11:51 AM, [email protected] wrote: > Five minutes after a closed my interactive interpreters windows, > the day I tested this stuff. I though: > "Too bad I did not noted the extremely bad cases I found, I'm pretty > sure, this problem will arrive on the table". Reading through this thread (which is entertaining), I am reminded of the old saying, "premature optimization is the root of all evil." This "problem" that you have discovered, if fixed the way you propose, (4-byte USC-4 representation internally always) would be just such a premature optimization. It would come at a high cost with very little real-world impact. As others have made abundantly clear, the overhead of changing internal string representations is a cost that's only manifest during the creation of the immutable string object. If your code is doing a lot of operations on immutable strings, which by definition creates new immutable string objects, then the real speed problem is in your algorithm. If you are working on a string as if it were a buffer, doing many searches, replaces, etc, then you need to work on an object designed for IO, such as io.StringIO. If implemented half correctly, I imagine that StringIO uses internally the widest possible character representation in the buffer. I could be wrong here. As to your other problem, Python generally tries to follow unicode encoding rules to the letter. Thus if a piece of text cannot be represented in the character set of the terminal, then Python will properly err out. Other languages you have tried, likely fudge it somehow. Display what they can, or something similar. In general the Windows command window is an outdated thing that no serious programmer can rely on to display unicode text. Use a proper GUI api, or use a better terminal that can handle utf-8. The TLDR version: You're right that converting string representations internally incurs overhead, but if your program is slow because of this you're doing it wrong. It's not symptomatic of some python disease. -- http://mail.python.org/mailman/listinfo/python-list
Re: New internal string format in 3.3
On 08/20/2012 07:17 AM, Roy Smith wrote: > In article , > Michael Torrie wrote: > >> Python generally tries to follow unicode >> encoding rules to the letter. Thus if a piece of text cannot be >> represented in the character set of the terminal, then Python will >> properly err out. Other languages you have tried, likely fudge it >> somehow. > > And if you want the "fudge it somehow" behavior (which is often very > useful!), there's always http://pypi.python.org/pypi/Unidecode/ Sweet tip, thanks! I often want to process text that has smart quotes, emdashes, etc, and convert them to plain old ascii quotes, dashes, ticks, etc. This will do that for me without resorting to a bunch of regexes. Bravo. -- http://mail.python.org/mailman/listinfo/python-list
Re: py2c - an open source Python to C/C++ is looking for developers
On 09/01/2012 09:15 PM, Ramchandra Apte wrote: > It converts to *pure* C/C++ *without* using Python or its API so that it can > be the same speed as C/C++ Sounds like a fun project for you. I hope you learn a lot doing it. That's reason enough for it. Do you plan to port all the standard python modules as well, though? Because Python modules, both in the standard library and third-party, are the main reasons that I use python. For example, PyGTK. Python is a great glue language. Since it can seamlessly interact with C and be extended in C, speed has never really been an issue for me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Flexible string representation, unicode, typography, ...
On 09/02/2012 12:58 PM, [email protected] wrote: > My rationale: very simple. > > 1) I never heard about something better than sticking with one > of the Unicode coding scheme. (genreral theory) > 2) I am not at all convinced by the "new" Py 3.3 algorithm. I'm not the > only one guy, who noticed problems. Arguing, "it is fast enough", is not > a correct answer. If this is true, why were you holding ho Google Go as an example of doing it right? Certainly Google Go doesn't line up with your rational. Go has both Strings and Runes. But strings are UTF-8-encoded bytes strings and Runes are 32-bit integers. They are not interchangeable without a costly encoding and decoding process. Even worse, indexing a Go string to get a "Rune" involves some very costly decoding that has to be done starting at the beginning of the string each time. In the worst case, Python's strings are as slow as Go because Python does the exact same thing as Go, but chooses between three encodings instead of just one. Best case scenario, Python's strings could be much faster than Go's because indexing through 2 of the 3 encodings is O(1) because they are constant-width encodings. If as you say, the latin-1 subset of UTF-8 is used, then UTF-8 indexing is O(1) too, otherwise it's probably O(n). -- http://mail.python.org/mailman/listinfo/python-list
