Re: Generator Frustration
On Jun 4, 2:27 pm, "TommyVee" wrote: > I'm using the SimPy package to run simulations. Anyone who's used this > package knows that the way it simulates process concurrency is through the > clever use of yield statements. Some of the code in my programs is very > complex and contains several repeating sequences of yield statements. I > want to combine these sequences into common functions. The problem of > course, is that once a yield gets put into a function, the function is now a > generator and its behavior changes. Is there any elegant way to do this? I > suppose I can do things like ping-pong yield statements, but that solutions > seems even uglier than having a very flat, single main routine with > repeating sequences. > > Thanks in advance. I actually found a reasonable answer to this, I think. If one of the called functions contains a yield, that function is by definition a generator, and will test as such with 'if type(result)==types.GeneratorType:'. This makes it possible for the function that calls the subroutine to either do its own yield, or to yield the result of the function's next 'yield' statement. I've got a class the run method of which calls the 'cycle' method of its derived class, as follows: while True: result= self.cycle(now()) # result may or may not be a generator if type(result)==types.GeneratorType: # Next is a generator, meaning it includes a 'yield'. # Otherwise, result should be None and cycle is a simple # function. try: yield result.next() while True: yield result.next() except StopIteration: pass else: # self.cycle() was a simple function, returning None- it's # done now. pass # It is time for this process to go back to sleep; all the yields # in self.cycle() have been processed. yield hold,self,self.nextCycleTime-now() -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator Frustration
On Jun 20, 9:42 pm, Terry Reedy wrote: > > A nomenclature note: a function with yield is a 'generator function'. It > is an instance of the 'function' class, same as for any other def > statement (or lambda expression). It returns an instance of class > 'generator, as you note here > > > and will test as such with 'if type(result)==types.GeneratorType:'. > > It is the result, and not the function, that is the generator (a type of > iterator). > > -- > Terry Jan Reedy Yes, quite right. I stand corrected. -Joel -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining digit in a list to make an integer
Harlin Seritt wrote:
> If anyone has time, would you mind explaining the code that Dan
Bishop
> was so kind as to point out to me:
>
> int(''.join(num1))
>
> This worked perfectly for me, however, I'm not sure that I understand
> it very well.
>
> Thanks,
>
> Harlin Seritt
''.join(list of strings) is a python idiom for fast string
concatenation. ''.join(num1) would give "145". The function int() is
then used to convert the resulting string into an integer.
--
http://mail.python.org/mailman/listinfo/python-list
Cross-platform time out decorator
I've been using this nice timing out decorator : http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307871 . The problem is that since it relies on sigalarm, it doesn't work under windows. Would anyone know how to do a cross-platform version? Thanks a lot! joel -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-platform time out decorator
On Sep 26, 12:21 pm, Joel <[EMAIL PROTECTED]> wrote: > I've been using this nice timing out decorator > :http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307871. The > problem is that since it relies on sigalarm, it doesn't work under > windows. Would anyone know how to do a cross-platform version? > > Thanks a lot! > > joel I found the solution : http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440569 describes a solution based on threads. I tested it and it works perfectly. -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-platform time out decorator
On Sep 27, 4:36 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Joel <[EMAIL PROTECTED]> writes: > > I found the solution : > >http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440569 > > describes a solution based on threads. I tested it and it works > > perfectly. > > Note that, unlike the original alarm code, it doesn't really interrupt > the timed-out method, it just returns the control back to the caller, > using an exception to mark that a timeout occurred. The "timed out" > code is still merrily running in the background. I don't know if it's > a problem in your case, but it's an important drawback. There should be a method to stop the thread though? I've never programmed thread stuff in python and wasn't able to find how to do it, would you happen to know how to "kill" the timed out thread? -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-platform time out decorator
On Sep 27, 10:40 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On 9/27/07, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > > > > > Joel <[EMAIL PROTECTED]> writes: > > > >> Note that, unlike the original alarm code, it doesn't really interrupt > > >> the timed-out method, it just returns the control back to the caller, > > >> using an exception to mark that a timeout occurred. The "timed out" > > >> code is still merrily running in the background. I don't know if it's > > >> a problem in your case, but it's an important drawback. > > > > There should be a method to stop the thread though? > > > Not in Python. Thread killing primitives differ between systems and > > are unsafe in general, so they're not exposed to the interpreter. On > > Windows you can attempt to use ctypes to get to TerminateThread, but > > you'll need to hack at an uncomfortably low level and be prepared to > > deal with the consequences, such as memory leaks. If the timeouts > > happen rarely and the code isn't under your control (so you have no > > recourse but to terminate the thread), it might be worth it though. > > -- > > You can use ctypes and the Python API to raise a Python exception in > the thread. Could you point me to an example of how to do that? > I don't normally mention this, because it has some > limitations, but it results in essentially the same effect as the > signal based method. They both have the limitation that C code can't > be interrupted. -- http://mail.python.org/mailman/listinfo/python-list
Boa constructor debugging - exec some code at breakpoint?
Hey there.. I'm using boa constructor to debug a python application. For my application, I need to insert break points and execute some piece of code interactively through shell or someother window when the breakpoint has been reached. Unfortunately the shell I think is a seperate process so whatever variables are set while executing in debugger dont appear in the shell when I try to print using print statement. Can anyone tell me how can I do this? Really appreciate any support, Thanks Joel P.S. Please CC a copy of reply to my email ID if possible. -- http://mail.python.org/mailman/listinfo/python-list
Boa constructor
Hi, In BOA constructor, is there any way to do the following: Once a breakpoint has reached, I want to enter some code and execute it. Can anyone tell me of a technique? Also input stream doesn't seem to work, I do a standard input read and then i enter something in the input window, but it isn't accepted. What could be the reason? Thanks Joel -- http://mail.python.org/mailman/listinfo/python-list
Re: Boa constructor
On Jan 12, 9:37 am, Joel <[EMAIL PROTECTED]> wrote: > Hi, > In BOA constructor, is there any way to do the following: > Once a breakpoint has reached, I want to enter some code > and execute it. > Can anyone tell me of a technique? > > Also input stream doesn't seem to work, I do a standard input read and > then i enter something in the input window, but it isn't accepted. > What could be the reason? > > Thanks > Joel I wanted to clarify, when I say "enter code", I mean I want to enter some custom code, like print a or something to see the condition of variable 'a' at the breakpoint. -- http://mail.python.org/mailman/listinfo/python-list
Re: Boa constructor debugging - exec some code at breakpoint?
Can you please tell me how this can be done.. are there any other IDEs for the same purpose if Boa can't do it? Joel On Jan 6, 11:01 am, Joel <[EMAIL PROTECTED]> wrote: > Hey there.. > I'm using boa constructor to debug a python application. For my > application, I need to insert break points and execute some piece of > code interactively through shell or someother window when the > breakpoint has been reached. Unfortunately the shell I think is a > seperate process so whatever variables are set while executing in > debugger dont appear in the shell when I try to print using print > statement. > > Can anyone tell me how can I do this? > > Really appreciate any support, Thanks > > Joel > P.S. Please CC a copy of reply to my email ID if possible. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for philosophers
On Sat, May 11, 2013 at 4:03 PM, Citizen Kant wrote: > Hi, > this could be seen as an extravagant subject but that is not my original > purpose. I still don't know if I want to become a programmer or not. My guess is that you don't want to be a programmer. Otherwise you would know that you did. > At this moment I'm just inspecting the environment. I'm making my way to > Python (and OOP in general) from a philosophical perspective or point of > view and try to set the more global definition of Python's core as an > "entity". In order to do that, and following Wittgenstein's indication > about that the true meaning of words doesn't reside on dictionaries but in > the use that we make of them, the starting question I make to myself about > Python is: which is the single and most basic use of Python as the entity > it is? I mean, beside programming, what's the single and most basic result > one can expect from "interacting" with it directly (interactive mode)? I > roughly came to the idea that Python could be considered as an *economic > mirror for data*, one that mainly *mirrors* the data the programmer types > on its black surface, not exactly as the programmer originally typed it, > but expressed in the most economic way possible. That's to say, for > example, if one types >>>1+1 Python reflects >>>2. When data appears > between apostrophes, then the mirror reflects, again, the same but > expressed in the most economic way possible (that's to say without the > apostrophes). > > So, would it be legal (true) to define Python's core as an entity that > mirrors whatever data one presents to it (or feed it with) showing back the > most shortened expression of that data? > > Don't get me wrong. I can see the big picture and the amazing things that > programmers write on Python, it's just that my question points to the > lowest level of it's existence. > > Thanks a lot for your time. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On Tue, May 28, 2013 at 2:08 PM, 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. > -- > http://mail.python.org/mailman/listinfo/python-list > http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect Could this be the problem? ;) -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
No On May 28, 2013 3:48 PM, "Carlos Nepomuceno" wrote: > Are there Python 'preprocessor directives'? > > I'd like to have something like '#ifdef' to mix code from Python 2 and 3 > in a single file. > > Is that possible? How? > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
On Tue, May 28, 2013 at 6:18 PM, Mark Lawrence wrote: > On 28/05/2013 20:46, Carlos Nepomuceno wrote: > >> Are there Python 'preprocessor directives'? >> >> I'd like to have something like '#ifdef' to mix code from Python 2 and 3 >> in a single file. >> >> Is that possible? How? >> >> > https://pypi.python.org/pypi/**six/1.3.0<https://pypi.python.org/pypi/six/1.3.0> > > -- > If you're using GoogleCrap™ please read this http://wiki.python.org/moin/* > *GoogleGroupsPython <http://wiki.python.org/moin/GoogleGroupsPython>. > > Mark Lawrence > > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > my original response was from cell phone. I just answered that you can't do ifdefs, implying that there is no preprocessor in python. I learned a lot of things I didn't know reading the thread, but I wonder if it is a good idea in general to try to write code like this. -- combined 2.x/3.x codebase can be a bear to maintain. I wouldn't do it unless there was some imposing reason that I must. Its not just print() -- that isn't bad, but changes in module names (urllib), arithmetic, and unicode especially make this idea in general, very tricky. Pity the next developer who needs to try to maintain it. So, maybe you CAN do it, but SHOULD you want to do it? -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On Tue, Jun 4, 2013 at 11:11 AM, Chris Angelico wrote: > On Wed, Jun 5, 2013 at 1:06 AM, Chris “Kwpolska” Warrick > wrote: > >> [1] http://www.oocities.org/timessquare/4753/bofh.htm > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > > > > Please link and read at the BOFH’s page. [0] is the page and [1] is > > this exact story. > > > > [0]: http://bofh.ntk.net/BOFH/index.php > > [1]: http://bofh.ntk.net/BOFH//bastard07.php > > Hrm. I went poking on ntk.net but couldn't find it, so I posted a > different link rather than go with no link. Thanks for finding the > official page, that's what I'd prefer normally. > > I think SimonT mucked up something a while ago and lost himself a pile > of search engine rank. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > reading this thread is like slowing down to see the car wreck on the other side of the highway. I think I feel bad for the people who are paying to host their stuff on the OP server. But maybe they get what they deserve. -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Source code to identify user through browser?
On Wed, Jun 5, 2013 at 9:08 AM, Gilles wrote: > Hello > > I was wondering if some Python module were available to identify a > user through their browser, like it's done on the Panopticlick site: > > http://panopticlick.eff.org/ > > I'd like to ban abusive users, and it seems like a good solution, > since few users will think of installing a different browser, and > there are few mainstream browsers anyway. > > Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list > depending upon the server you are using, there is a request object that contains information about the user (ip address, and lots of other stuff). Maybe that will help you. -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: I just wrote my first Python program a guessing game and it exits with an error I get this.
On Wed, Jun 5, 2013 at 12:15 PM, Zachary Ware wrote: > On Wed, Jun 5, 2013 at 10:35 AM, Armando Montes De Oca > wrote: > > Thank You now the program exits with: > > (program exited with code: 0) > > Press return to continue > > > > > > Is there a way to get the line (program exited with code: 0) to say > something > > > > like: "The game will end now" > > > > Press return to contine > > To whom are you replying? Please quote what (and who) you are > replying to to provide context. > > As for how to change that line, it depends on how you're running the > script. > -- > http://mail.python.org/mailman/listinfo/python-list > The program exited with code: 0 is being provided by geany after your program has run. If instead you open up a terminal and type: python your_program.py You will run your program and get an error message from python. You can get rid of the error message by using try/except, but you may not have learned about that yet. good luck -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On Wed, Jun 5, 2013 at 12:24 PM, Chris Angelico wrote: > On Wed, Jun 5, 2013 at 9:07 PM, Νικόλαος Κούρας > wrote: > > I will understand by his attitude in general if he is likely to help me > or not. > > How much of my attitude did you read before you decided I would trust > you? Posts like this: > > http://mail.python.org/pipermail/python-list/2013-June/648428.html > http://mail.python.org/pipermail/python-list/2013-June/648496.html > > and especially this: > > http://mail.python.org/pipermail/python-list/2013-June/648459.html > > state fairly clearly what I'm intending. I was NOT planning to solve > your problem. I was planning all along to do exactly what I did: > search for some proof that I had full access, email it to the persons > concerned, then leave without doing any actual damage. > > So if you were *that wrong* about me, what makes you think you can > judge someone else safely? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > To solve the OPs problems once and for all, I believe we need to know his social security number and his mother's maiden name. (Yes, i know SSN is for US but... ) -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Now, you were right about my bad mouth because iam going to tell you to sod off. >Well, if he had ethics he would have told me that his intentiosn were to screw my business and also he could actually tried to help me out. Many times I've seen people here give you their best advice and you come back seemingly having not even read what they had to say. You just whine and say someone should help you, even though many have already done that. You don't take the help. Now in this case, Chris more or less proved my point. I've been reading along, and he said exactly what he would do if you gave him root access to your account. He said he would write to your users and explain to them the peril of how you run your hosting service. He didn't say he would help you. Go back and read exactly what he said, and then take a deep breath and do some introspection of your own conduct. He basically said, don't touch the stove, its hot. And you touched the stove and then complained. You act very poorly here. Grow up >I'am not incompetentm i;m a beginner and i learn along the way, also i ahve a hostign company and 3rd level tech that support me when it come to system administration. I think you are incompetent. No one knows everything, and groups like this are a great place to learn more. But part of being competent is being careful. You are reckless. You work on a live server for which you have paying customers. You make endless changes to your code without taking the time to go off and google for information about the topic you are struggling with. Your live site should probably have been put together using a framework, but that would have required you to read about, experiment with and use a framework. You write html code in the midst of your python code. You have endless encoding/decoding issues, but you have never apparently read the many articles on how unicode works. Have some respect for the science and craft of making good software. On Wed, Jun 5, 2013 at 3:03 PM, Chris Angelico wrote: > On Thu, Jun 6, 2013 at 4:55 AM, rusi wrote: > > If you obdurately, obstinately, insistently, incessantly behave like > > an asshole, you leave no-one the choice but to treat you like an > > asshole. > > This is Python. We duck-type people. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: I just wrote my first Python program a guessing game and it exits with an error I get this.
On Wed, Jun 5, 2013 at 4:18 PM, Thomas Murphy wrote: > Goldstick which seems Jewish to me. I would think as a Gentile Heathen > Jesus save us this would project a need for a good sex life > > *WAT* > * > * > I second the WAT. You are a strange person. I think you were being offensive. I can't help you with your sex life. Sorry kid. > ** > * > * > Armando, are you understanding that input and raw_input make Python do > very different things, and this is dependent of the version of Python > you're using? Folks aren't being pedantic, it's critical to giving you a > good answer. > > > So it seems you changed your input to raw_input and now your program works. But you don't like the final message. Do you know what this line does: sys.exit(0) If you don't, then you shouldn't have put it in your program. Google it "python sys.exit(0)". I imagine that is what is causing the message you are concerned with. Try removing that line (each place you have them) and see what happens. Also, there is a python-tutor list that may be a better place for you to post. Try being polite. You may be quite a bit more lost than you realize! > On Wed, Jun 5, 2013 at 3:59 PM, Armando Montes De Oca < > [email protected]> wrote: > >> Well I am replying to To whom it may concern at this point I am a bit >> lost. I posted all my code. I am not taking classes on this nor do I have a >> book I followed a guy on You Tube. I am a student but I heard Python is a >> good language to learn in conjunction with C++ and Perl for example. I have >> taken Visual Basic 2010 last semester so keep thinking for me if you like >> if not when I can get a Python book or lesson. Joel Goldstick seems the >> more "professorly" so far by telling me the right thing of I have not >> learned something yet. Also with a name like Goldstick which seems Jewish >> to me. I would think as a Gentile Heathen Jesus save us this would project >> a need for a good sex life. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Sincerely, > Thomas Murphy > Code Ninja > 646.957.6115 > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Redirecting to a third party site with injected HTML
On Sun, Jun 9, 2013 at 1:09 PM, wrote: > Hi all, > > new to group and pretty new to python. > > I'm working on a new project and i want to receive a request from a user > and to redirect him to a third party site, but on the page after i redirect > my users i want to them to see injected html (on the third party site.) > > i'm not really sure how to approach this problem.. > hints :) > > regards, > Guy > -- > http://mail.python.org/mailman/listinfo/python-list > you can do redirect easily, but you can't inject html in 3rd party without permission. At any rate, how is this a python question? -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Redirecting to a third party site with injected HTML
On Sun, Jun 9, 2013 at 1:52 PM, wrote: > its a python question since the request is received on a python server and > i thought that > there may be a way to so from the server that sends the response to the > user... > > On Sunday, June 9, 2013 8:22:17 PM UTC+3, Fábio Santos wrote: > > On 9 Jun 2013 18:15, wrote: > > > > > > > > > > Hi all, > > > > > > > > > > new to group and pretty new to python. > > > > > > > > > > I'm working on a new project and i want to receive a request from a > user and to redirect him to a third party site, but on the page after i > redirect my users i want to them to see injected html (on the third party > site.) > > > > > > > > > > > > i'm not really sure how to approach this problem.. > > > > > hints :) > > > > > > > > > > regards, > > > > > Guy > > > > What web framework are you using? > > > > This does not seem like a python question, instead a HTML/JavaScript one. > -- > http://mail.python.org/mailman/listinfo/python-list > unless you hack into 3rd party, you can't alter that site -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On Tue, Jun 4, 2013 at 1:12 PM, Νικόλαος Κούρας wrote: > Τη Τρίτη, 4 Ιουνίου 2013 8:09:18 μ.μ. UTC+3, ο χρήστης Chris Angelico > έγραψε: > > On Wed, Jun 5, 2013 at 3:02 AM, Νικόλαος Κούρας > wrote: > > > > > I'm willing to let someone with full root access to my webhost to see > thigns from the inside. > > > > > > > > > > Does someone want to take o allok or at elast tell me what else i need > to try, that hasn't been tried out yet? > > > > > > > > You need to read up on what happens when you enter Dummy Mode and give > > > > someone full root access to your web host. You really REALLY need to > > > > understand what that means before you offer random strangers that kind > > > > of access to someone else's data. > > > > > > > > I've half a mind to take you up on your offer, then go look for > > > > personal and private info from your clients, and email it to them > > > > (along with a link to this thread) to point out what's going on. > > > > > > > > ChrisA > > I know what full root access mean. > I also trust you. > I'm hopeless man, its 1 week now dealing with this. > -- > http://mail.python.org/mailman/listinfo/python-list > I trust you too Chris! -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: My son wants me to teach him Python
On Wed, Jun 12, 2013 at 4:02 PM, Chris Angelico wrote: > On Thu, Jun 13, 2013 at 5:46 AM, John Ladasky > wrote: > > He's a smart kid, but prefers to be shown, to be tutored, rather than > having the patience to sit down and RTFM. Have any of you been down this > road before? I would appreciate it if you would share your experiences, or > provide resource material. > > > There is a google course in python on videos. I believe it has time outs for doing assignments. Here is where you go to get started https://developers.google.com/edu/python/ > > Actually yes! My dad (whose name is also John) asked me the same > question, regarding one of my siblings. I put the question to the > list, and got back a number of excellent and most useful answers > regarding book recommendations, and we ended up going with (if memory > serves me) Think Python [1]. It seems to be doing fine, though I've > overheard some issues regarding Tkinter, Python 3.3, and Debian > Squeeze. So be aware that you may have to compile your own Python, and > if you do, you may have to look at what modules get compiled in. But > from my experience of building Python, that's not difficult. > > [1] http://www.greenteapress.com/thinkpython/ I think, but DNS on this > computer is broken at the moment so I can't verify that link > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrong website loaded when other requested
On Wed, Jun 12, 2013 at 1:33 PM, Νικόλαος Κούρας wrote:
> ==
> RewriteEngine Off
> RewriteCond %{REQUEST_FILENAME} -f
> RewriteRule ^/?(.+\.html) /cgi-bin/metrites.py?file=%{**REQUEST_FILENAME}
> [L,PT,QSA]
> ==
>
> [code]
> file = form.getvalue('file')
> page = form.getvalue('page')
>
> if not page and os.path.exists( file ):
> # it is an html template
> page = file.replace( '/home/dauwin/public_html/', '' )
> elif page or form.getvalue('show'):
> # it is a python script
> page = page..replace( '/home/dauwin/public_html/cgi-**bin/', '' )
> else:
> #when everything else fails fallback
> page = "index.html"
>
>
>
>
> if page.endswith('.html'):
> with open( '/home/dauwin/public_html/' + page,
> encoding='utf-8' ) as f:
> htmlpage = f.read()
> htmlpage = htmlpage % (quote, music)
> template = htmlpage + counter
> elif page.endswith('.py'):
> pypage = subprocess.check_output(
> '/home/dauwin/public_html/cgi-**bin/' + page )
> pypage = pypage.decode('utf-8').**replace( 'Content-type:
> text/html; charset=utf-8', '' )
> template = pypage + counter
>
> print( template )
> [/code]
>
> Everything as you see point to 'dauwin' username, yet the error still says:
>
> [code]
> [Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] File
> "/home/nikos/public_html/cgi-**bin/metrites.py", line 219, in ,
> referer: http://superhost.gr/
> [Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] with open(
> '/home/nikos/public_html/' + page, encoding='utf-8' ) as f:, referer:
> http://superhost.gr/
> [Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]
> FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd
> \\u03c5\\u03c0\\u03ac\\u03c1\\**u03c7\\u03b5\\u03b9
> \\u03c4\\u03ad\\u03c4\\u03bf\\**u03b9\\u03bf
> \\u03b1\\u03c1\\u03c7\\u03b5\\**u03af\\u03bf \\u03ae
> \\u03ba\\u03b1\\u03c4\\u03ac\\**u03bb\\u03bf\\u03b3\\u03bf\\**u03c2:
> '/home/nikos/public_html//**home/dauwin/public_html/index.**html',
> referer: http://superhost.gr/
> [/code]
>
>
> Notice that you have the file path you want concatenated to your
/home/nikos/... stuff in the line above. Look in your code to find out
why. Fix that. Lather, rinse, repeat
> Why is pointing to /home/nikos isntead of /home/dauwin ?
>
> this is what a smash my head to the wall to understand.
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
--
Joel Goldstick
http://joelgoldstick.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Version Control Software
git or hg. but git is most popular and very easy to learn. Its also great for distributed develpment On Wed, Jun 12, 2013 at 7:36 PM, Mark Janssen wrote: > > I am looking for an appropriate version control software for python > development, and need professionals' help to make a good decision. > Currently I am considering four software: git, SVN, CVS, and Mercurial. > > I'm not real experienced, but I understand that SVN is good if your > hosting your own code base, and CVS is hardly used anymore as it > doesn't support atomic commits (when having many developers work on > the same code base). Git and hg have ben vying for several years with > no clear winner, yet > > -- > MarkJ > Tacoma, Washington > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrong website loaded when other requested
So Nick, I am top posting because I don't think you read your replies. I
replied yesterday.
Read this line below. Read the line below. READ it. READ IT.. each
letter. READ it:
[Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]
FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd
\\u03c5\\u03c0\\u03ac\\u03c1\\
>
> u03c7\\u03b5\\u03b9 \\u03c4\\u03ad\\u03c4\\u03bf\\u03b9\\u03bf
> \\u03b1\\u03c1\\u03c7\\u03b5\\u03af\\u03bf \\u03ae
> \\u03ba\\u03b1\\u03c4\\u03ac\\u03bb\\u03bf\\u03b3\\u03bf\\u03c2:
> '/home/nikos/public_html//home/dauwin/public_html/index.html', referer:
> http://superhost.gr/
> [/code]
>
DO YOU SEE THIS PART:
'/home/nikos/public_html//home/dauwin/public_html/index.html', referer:
http://superhost.gr/
Do you see that it prepends your nikos path the your dauwin path and file
name. It isn't replacing one with the other. Somewhere in your SFBI mess
of code you perhaps have set the nikos path as the start of a filename.
Check that out
DID YOU READ THIS? DID YOU THINK ABOUT IT. Also look up SFBI. It is a
good name for you
> [/code]
>
On Wed, Jun 12, 2013 at 4:35 PM, Joel Goldstick wrote:
>
>
>
> On Wed, Jun 12, 2013 at 1:33 PM, Νικόλαος Κούρας wrote:
>
>> ==
>> RewriteEngine Off
>> RewriteCond %{REQUEST_FILENAME} -f
>> RewriteRule ^/?(.+\.html) /cgi-bin/metrites.py?file=%{**REQUEST_FILENAME}
>> [L,PT,QSA]
>> ==
>>
>> [code]
>> file = form.getvalue('file')
>> page = form.getvalue('page')
>>
>> if not page and os.path.exists( file ):
>> # it is an html template
>> page = file.replace( '/home/dauwin/public_html/', '' )
>> elif page or form.getvalue('show'):
>> # it is a python script
>> page = page..replace( '/home/dauwin/public_html/cgi-**bin/', '' )
>> else:
>> #when everything else fails fallback
>> page = "index.html"
>>
>>
>>
>>
>> if page.endswith('.html'):
>> with open( '/home/dauwin/public_html/' + page,
>> encoding='utf-8' ) as f:
>> htmlpage = f.read()
>> htmlpage = htmlpage % (quote, music)
>> template = htmlpage + counter
>> elif page.endswith('.py'):
>> pypage = subprocess.check_output(
>> '/home/dauwin/public_html/cgi-**bin/' + page )
>> pypage = pypage.decode('utf-8').**replace(
>> 'Content-type: text/html; charset=utf-8', '' )
>> template = pypage + counter
>>
>> print( template )
>> [/code]
>>
>> Everything as you see point to 'dauwin' username, yet the error still
>> says:
>>
>> [code]
>> [Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] File
>> "/home/nikos/public_html/cgi-**bin/metrites.py", line 219, in ,
>> referer: http://superhost.gr/
>> [Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] with open(
>> '/home/nikos/public_html/' + page, encoding='utf-8' ) as f:, referer:
>> http://superhost.gr/
>> [Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173]
>> FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd
>> \\u03c5\\u03c0\\u03ac\\u03c1\\**u03c7\\u03b5\\u03b9
>> \\u03c4\\u03ad\\u03c4\\u03bf\\**u03b9\\u03bf
>> \\u03b1\\u03c1\\u03c7\\u03b5\\**u03af\\u03bf \\u03ae
>> \\u03ba\\u03b1\\u03c4\\u03ac\\**u03bb\\u03bf\\u03b3\\u03bf\\**u03c2:
>> '/home/nikos/public_html//**home/dauwin/public_html/index.**html',
>> referer: http://superhost.gr/
>> [/code]
>>
>>
>> Notice that you have the file path you want concatenated to your
> /home/nikos/... stuff in the line above. Look in your code to find out
> why. Fix that. Lather, rinse, repeat
>
>> Why is pointing to /home/nikos isntead of /home/dauwin ?
>>
>> this is what a smash my head to the wall to understand.
>> --
>> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>>
>
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com
>
--
Joel Goldstick
http://joelgoldstick.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Wrong website loaded when other requested
On Thu, Jun 13, 2013 at 2:10 PM, Nick the Gr33k wrote: > > > Τη Πέμπτη, 13 Ιουνίου 2013 7:52:27 μ.μ. UTC+3, ο χρήστης Νικόλαος Κούρας > έγραψε: > > On 13/6/2013 6:35 μμ, Joel Goldstick wrote: > > > >> [Tue Jun 11 21:59:31 2013] [error] [client 79.103.41.173] > > > >> FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd > > > >> \\u03c5\\u03c0\\u03ac\\u03c1\\ > > > >> > > > >> u03c7\\u03b5\\u03b9 \\u03c4\\u03ad\\u03c4\\u03bf\\**u03b9\\u03bf > > > >> \\u03b1\\u03c1\\u03c7\\u03b5\\**u03af\\u03bf \\u03ae > > > >> \\u03ba\\u03b1\\u03c4\\u03ac\\**u03bb\\u03bf\\u03b3\\u03bf\\** > u03c2: > > > >> '/home/nikos/public_html//**home/dauwin/public_html/index.**html', > > > >> referer: http://superhost.gr/ > > > >> [/code] > > > >> > > > >> DO YOU SEE THIS PART: > > > >> '/home/nikos/public_html//**home/dauwin/public_html/index.**html', > > > >> referer: http://superhost.gr/ > > > >> > > > >> Do you see that it prepends your nikos path the your dauwin path and > > > >> file name. It isn't replacing one with the other. Somewhere in your > > > >> SFBI mess of code you perhaps have set the nikos path as the start of a > > > >> filename. Check that out > > > > > > > > yes i saw your post Joel, > > > > > > > > After research i am under the impression that i'am in need for UserDir > > > > directive as it essentially allows you to use User Home directories as > > > > web directories... > > > > > > > > So after reading this: > > > > http://centosforge.com/node/**how-get-userdir-user-specific-** > publichtml-working-apache-**centos-6<http://centosforge.com/node/how-get-userdir-user-specific-publichtml-working-apache-centos-6> > > > > i did this: > > > > > > > > > > > > > > > > UserDir public_html > > > > > > > > > > > > #UserDir disabled > > > > UserDir "enabled *" > > > > UserDir "disabled root" > > > > > > > > > > > > > > > > > > > > root@nikos [~]# chmod 711 /home > > > > root@nikos [~]# chmod 711 /home/nikos > > > > root@nikos [~]# chmod 755 /home/nikos/public_html/ > > > > root@nikos [~]# chmod o+r /home/nikos/public_html/index.**html > > > > root@nikos [~]# chmod 711 /home/dauwin > > > > root@nikos [~]# chmod 755 /home/dauwin/public_html/ > > > > root@nikos [~]# chmod o+r /home/dauwin/public_html/**index.html > > > > root@nikos [~]# > > > > > > > > setsebool -P httpd_enable_homedirs true > > > > chcon -R -t httpd_sys_content_t /home/testuser/public_html > > > > (the last one one failed though) > > > > > > > > the i restarted Apache but the problem is still there. > > > > > > > > === > > > > [email protected] [~]# [Thu Jun 13 19:50:57 2013] [error] [client > > > > 79.103.41.173] Error in sys.excepthook: > > > > [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] ValueError: > > > > underlying buffer has been detached > > > > [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] > > > > [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] Original > > > > exception was: > > > > [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] Traceback > > > > (most recent call last): > > > > [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] File > > > > > "/home/nikos/public_html/cgi-**bin/metrites.py", line 213, in > > > > [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] with open( > > > > > '/home/nikos/public_html/' + page, encoding='utf-8' ) as f: > > > > [Thu Jun 13 19:50:57 2013] [error] [client 79.103.41.173] > > > > > FileNotFoundError: [Errno 2] \\u0394\\u03b5\\u03bd > > > > \\u03c5\\u03c0\\u03ac\\u03c1\\**u03c7\\u03b5\\u03b9 > > > > \\u03c4\\u03ad\\u03c4\\u03bf\\**u03b9\\u03bf > > > > \\u03b1\\u03c1\\u03c7\\u03b5\\**u03af\\u03bf \\u03ae > > > > \\u03ba\\u03b1\\u03c4\\u03ac\\**u03bb\\u03bf\\u03b3\\u03bf\\**u03c2: > > > > '/home/nikos/public_html//**home/dauwin/public_html/index.**html' > SECOND TIME: I'm not an apache wizard, and I'm too self important to really look through all of your code. i don't getting germs. But, once again: your code is not finding a file named this: '/home/nikos/public_html//home/dauwin/public_html/index.html' The first part of this file path is:'/home/nikos/public_html After that are TWO forward slashes which remind me of http:// and following that is the path you want. so, you need to put new batteries in your brain, look through your mess and figure out what creates the wrong file name for you > > > > > > please take an overall look at my httpd.conf at > http://pastebin.com/Pb3VbNC9 in case you want to examine somehting else. > > Thank you very much. > > > -- > What is now proved was at first only imagined! > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a Super Simple WWW Link, Copy, & Paste into Spreadsheet Program
there is a python module that reads and writes to excel files. look for that On Thu, Jun 13, 2013 at 3:28 PM, wrote: > Hi, I'm new to Python. Would someone be able to write me and/or to show me > how to write a simple program that: > > 1-follows a hyperlink from MS Excel to the internet (one of many links > like this, http://www.zipdatamaps.com/76180, for e.g.) and then, > > 2-copies some data (a population number, e.g. 54195) and then, > > 3-pastes that data back into the same MS Excel spreadsheet, into the > adjacent cell. > > ... and that’s it... row after row of hyperlinks all in one column... > > Please, please help me my wrist is starting to hurt a lot. You would have > my greatest appreciation for your help! > > thank you, Buford > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
go away Nick. Go far away. You are not a good person. You are not even a good Troll. You are just nick the *ick. You should take up something you can do better than this.. like maybe sleeping On Fri, Jun 14, 2013 at 8:36 AM, Nick the Gr33k wrote: > On 14/6/2013 2:09 μμ, Antoon Pardon wrote: > >> Op 14-06-13 11:32, Nick the Gr33k schreef: >> >> I'mm not trolling man, i just have hard time understanding why numbers >>> acts as strings. >>> >> They don't. No body claimed numbers acted like strings. What was >> explained, >> >> was that when numbers are displayed, they are converted into a notational >> string, which is then displayed. This to clear you of your confusion >> between >> numerals and numbers which you displayed by writing something like "the >> binary representation as a number" >> >> Hold on. > > number = an abstract sense > numeral = ? > notation = ? > represenation = ? > > > -- > What is now proved was at first only imagined! > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questiosn about encoding
let's cut to the chase and start with telling us what you DO know Nick.
That would take less typing
On Fri, Jun 14, 2013 at 9:58 AM, Nick the Gr33k wrote:
> On 14/6/2013 1:14 μμ, Cameron Simpson wrote:
>
>> Normally a character in a b'...' item represents the byte value
>> matching the character's Unicode ordinal value.
>>
>
> The only thing that i didn't understood is this line.
> First please tell me what is a byte value
>
>
> \x1b is a sequence you find inside strings (and "byte" strings, the
>> b'...' format).
>>
>
> \x1b is a character(ESC) represented in hex format
>
> b'\x1b' is a byte object that represents what?
>
>
> >>> chr(27).encode('utf-8')
> b'\x1b'
>
> >>> b'\x1b'.decode('utf-8')
> '\x1b'
>
> After decoding it gives the char ESC in hex format
> Shouldn't it result in value 27 which is the ordinal of ESC ?
>
> > No, I mean conceptually, there is no difference between a code-point
>
> > and its ordinal value. They are the same thing.
>
> Why Unicode charset doesn't just contain characters, but instead it
> contains a mapping of (characters <--> ordinals) ?
>
> I mean what we do is to encode a character like chr(65).encode('utf-8')
>
> What's the reason of existence of its corresponding ordinal value since it
> doesn't get involved into the encoding process?
>
> Thank you very much for taking the time to explain.
>
> --
> What is now proved was at first only imagined!
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
--
Joel Goldstick
http://joelgoldstick.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: A few questiosn about encoding
On Sat, Jun 15, 2013 at 11:14 AM, Nick the Gr33k wrote: > On 15/6/2013 5:59 μμ, Roy Smith wrote: > > And, yes, especially in networking, everybody talks about octets when >> they want to make sure people understand what they mean. >> > > 1 byte = 8 bits > > in networking though since we do not use encoding schemes with variable > lengths like utf-8 is, how do we separate when a byte value start and when > it stops? > > do we need a start bit and a stop bit for that? > > > And this is specific to python how? > > > > -- > What is now proved was at first only imagined! > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python to automatically boot my computer at a specific time and play a podcast
On Sun, Jun 16, 2013 at 3:06 PM, C. N. Desrosiers wrote: > Hi, > > I'm planning to buy a Macbook Air and I want to use it as a sort of alarm. > I'd like to write a program that boots my computer at a specific time, > loads iTunes, and starts playing a podcast. Is this sort of thing possible > in Python? > > Thanks in advance. > Since Macs run a version of Unix underneath you can write a cron job to get things started at a specific time. I'm not sure about the iTunes interface. Have you researched to see if it has and API? If it does, likely python could handle that. > > CND > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python to automatically boot my computer at a specific time and play a podcast
On Sun, Jun 16, 2013 at 3:22 PM, Steven D'Aprano < [email protected]> wrote: > On Sun, 16 Jun 2013 12:06:08 -0700, C. N. Desrosiers wrote: > > > Hi, > > > > I'm planning to buy a Macbook Air and I want to use it as a sort of > > alarm. I'd like to write a program that boots my computer at a specific > > time, > > If your computer is turned off, how is the program supposed to run? > I was thinking maybe it could in some sleep mode that still ran cron jobs. but I am totally guessing that. If its OFF off then you might need another computer attached to a robot arm that could push the on button first! > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On Sun, Jun 16, 2013 at 2:39 PM, Antoon Pardon wrote: > Op 15-06-13 21:54, [email protected] schreef: > > On 06/15/2013 12:18 PM, rusi wrote: >> >>> On Jun 15, 10:52 pm, Steven D'Aprano>> +comp.lang.pyt...@pearwood.**info > >>> wrote: >>> >>>> On Sat, 15 Jun 2013 10:36:00 -0700, rusi wrote: >>>> >>>>> With you as our spamming-guru, Onward! Sky is the limit! >>>>> >>>> >>>> If you're going to continue making unproductive, off-topic, inflammatory >>>> posts that prolong these already excessively large threads, Nikos won't >>>> be the only one kill-filed. >>>> >>> >>> At least two people -- Alex and Antoon -- have told you that by >>> supporting Nikos, when everyone else wants him off list, you are part >>> of the problem. >>> >> >> Nikos is only secondarily the problem, Steven not at all. >> >> The primary problem is a (relatively small) number of people >> who respond to every post by Nikos with a barrage of insults, >> demands, (what they think are) witty repartee, hints intended >> to "make" Nikos learn something, useless (to Nikos) links, >> new threads to discuss the "Nikos problem", and other trash >> that is far more obnoxious that anything Nikos posts and just >> serves to egg him on. >> > > Sorry but this is IMO a false equivallence. It ignores the > important distinction between action and reaction. Does > this number of people post a barrage of insult to no matter > who? And you may find those responses more obnoxious they > propbably are the reactions of people who are utterly fed > up and think that if nobody is concerned about their annoyance > they don't have to b econcerned about the annoyance of others > either. > > > Steven's advice on how to deal with Nikos was probably the >> most sensible thing I've seen posted here on the subject. >> > > Most sensible for what purpose? As far as I can see Steven's > advice will just prolong the cycle of Nikos continuing to ask > for spoonfeeding, showing very litle signs of understanding > and keeping to hop from one problem/bug to the next until > the mailing list has finished his project at which point > he will probably start something new. > > If nikos's project was a college project we would have told > him he has to make his homework himself. But now he is earning > money with it, you seem to find it acceptable his job is done > for him. > > > I suggest that if you can and want to answer Nikos' question, >> do so directly and with a serious attempt address what it is >> he seems not to get, >> or >> killfile him and shut the fuck up. >> > > I suggest that if you want this to continue being a hospitable > place, you don't encourage asocial behaviour. His behaviour > may not bother you so much, but that shouldn't be the norm > because others are less bothered with the barrage of insults > Nikos is now receiving than with Nikos vampirizing this list, > because they consider those insults deserved. > > > -- > Antoon Pardon > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > I'm with Antoon on this. If you look at this group, it almost completely revolves around the guy from Greece with 3 or 4 or 5 different email addresses. His area of interest is repetitive: 1. Get me out of the Unicode hell that is my own making 2. Do my linux sys admin for me 3. I can't be bothered with understanding what more there is to making software other than cutting and pasting code that other people are willing to write for me 4. Go back to [1] and start again. If you need to understand unicode and or hex notation, or binary notation (and most likely you will if you write code for a living), then go learn about those things. If you are unwilling to do that, then go away. If you think its best to help this person, and be kind to him, and encourage him to become a better citizen, please remember that being inviting to a person who ruins the party for everyone is not being respectful of everyone else. All the while monopolizing many threads >From my perspective there seems to be some interesting people here with a wide array of experience and knowledge, whose understand and opinions I find fun and useful to read. All of that is drowned out by the freight train from superhost.gr -- Joel Goldstick http://joelgoldstick.com -- 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 Mon, Jun 17, 2013 at 11:55 AM, Simpleton wrote: > On 17/6/2013 5:22 μμ, Terry Reedy wrote: > >> On 6/17/2013 7:34 AM, Simpleton wrote: >> >>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: >>> >>>> Now, in languages like Python, Ruby, Java, and many others, there is no >>>> table of memory addresses. Instead, there is a namespace, which is an >>>> association between some name and some value: >>>> >>>> global namespace: >>>> x --> 23 >>>> y --> "hello world" >>>> >>> >>> First of all thanks for the excellent and detailed explanation Steven. >>> >>> As for namespace: >>> >>> a = 5 >>> >>> 1. a is associated to some memory location >>> 2. the latter holds value 5 >>> >> >> This is backwards. If the interpreter puts 5 in a *permanent* 'memory >> location' (which is not required by the language!), then it can >> associate 'a' with 5 by associating it with the memory location. CPython >> does this, but some other computer implementations do not. >> > > Please tell me how do i need to understand the sentence > 'a' is being associated with number 5 in detail. > > Why don't we access the desired value we want to, by referencing to that > value's memory location directly instead of using namespaces wich is an > indirect call? > > i feel we have 3 things here > > a , memory address of a stored value, actual stored value > > So is it safe to say that in Python a == &a ? (& stands for memory >>> address) >>> >>> is the above correct? >>> >> >> When you interpret Python code, do you put data in locations with >> integer addresses? >> > > I lost you here. > > > > -- > What is now proved was at first only imagined! > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > Read and study this. Then come back and ask again. Don't think of physical representation of memory with actual binary addresses. Python is not assembler. Neither is it C (sometimes called high level assembler) http://docs.python.org/2/tutorial/classes.html#python-scopes-and-namespaces -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with Python documentation [Re: Don't feed the troll...]
On Mon, Jun 17, 2013 at 6:50 PM, Steven D'Aprano < [email protected]> wrote: > On Mon, 17 Jun 2013 07:41:54 -0700, rurpy wrote: > > > On 06/17/2013 01:23 AM, Chris Angelico wrote: > >> On Mon, Jun 17, 2013 at 3:04 PM, Ferrous Cranus > >> wrote: > >>> The only thing i'm feeling guilty is that instead of reading help > >>> files and PEP's which seem too technical for me, i prefer the live > >>> help of an actual expert human being. > >> > >> This is definitely a reason to feel guilty. You are asking people to > >> provide live help for free, rather than simply reading the > >> documentation. > > > > It is NOT a matter of simply reading the documentation. I have posted > > here several times as have many others about some of the problems the > > documentation has, especially for people who don't already know Python. > > This is very reasonable. And nobody -- well, at least not me, and > probably not Chris -- expects that reading the documentation will > suddenly cause the light to shine for every beginner who reads it. Often > the official docs are written with an expected audience who already knows > the language well. > > But in context, Nikos has been programming Python long enough, and he's > been told often enough, that his FIRST stop should be the documentation, > and us second. Not what he does now, which is to make us his first, > second, third, fourth, fifth, sixth, seventh and eighth stops. > > (Are you paying attention Nikos?) > > But speaking more generally, yes, you are right, the docs are not a > panacea. If they were, mailing lists like this, and websites like > StackOverflow, would not exist. > > > I read the python docs. I've gone through the tutorials. If not the first time, or the second, I get that Aha moment with additional reads. Some people say they learn better by other methods than reading. In that case, google like crazy because python has lots of pycon stuff online in video form, and there is the google course. and many others. If people interaction is what you need, find, and visit your local meetup or user group. Lots of places have them. If you don't have one near you, maybe you could start one so you would have local help and back and forth (fourth?). I think its great to read a question here and get a link for an answer. gives me somewhere to go explore more. If you reject these ways of learning for the single method of asking.. fix my code. Then you will never get good at this craft anyway. Its not the answers that are important, its discovering how to find the answers that is really important. The old give a man a fish, vs teach a man to fish truism -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On Wed, Jun 19, 2013 at 11:31 AM, Rick Johnson wrote: > On Wednesday, June 19, 2013 8:58:19 AM UTC-5, [email protected] wrote: > > This is my first post in this group and the reason why I > > came across here is that, despite my complete lack of > > knowledge in the programming area, I received an order > > from my teacher to develop a visually interactive program, > > Ah teachers, you gotta love them! High on a power trip. > Drunk on tenure. Most of which are overpaid and > under-worked. Can't work with them, can't fire them! > > "HAY, TEACH-AH! Leave them kids alone!" > > > until 20th July, so we can participate in a kind of > > contest. My goal is to learn and program it by myself, as > > good as the time allows me. That said, what I seek here is > > advice from people who definitively have more experience > > than me on topics like: is it possible to develop this > > kind of program in such a short amount of time? > > > > What kinds of aspects of Python should I focus on > > learning? > > What tutorials and websites are out there that > > can help me? > DO you have access to google? > What kind of already done packages are out > > there that I can freely use, so I do not need to create > > all the aspects of the program froms scratch? It would be > > wise to give an abstract of the program. > > > > Full screen window -> Title and brief introductory text -> 3 Buttons > (Credits) (Instructions) and (Start) > > (Credits) -> Just plain text and a return button > > (Instructions) -> Just plain text and a return button > > (Start) -> Changes the screen so it displays a side-menu and a Canvas. > > Side menu -> X number of buttons (maybe 4 or 5) > > Buttons -> Clicked -> Submenu opens -> List of images > > -> Return button -> Back to side menu > > Image in List of images -> When clicked AND hold mouse button -> Make > copy > > -> if: dragged to canvas -> paste the copy in > place > > -> if: dragged anywhere else -> delete copy and > nothing happens > > On canvas: > > Image -> On click and drag can be moved > > -> Double click -> Opens menu -> Resize, Deform, Rotate, Color, > Brigthness, Contrast, Color Curve, Saturation > > Then, somewhere in cavas: > > Save option -> Prompt for file and user's name > > -> Prompt if users want printed copy or not -> Print > > -> After saved, display random slideshow in other monitor, > device or screen with the users' creations. > > > THis looks like a description of a program that is already completed > -- > http://mail.python.org/mailman/listinfo/python-list > This post seems so unlikely to me. What is the subject that this teacher of yours teaches? Do you know anyone who has every done any programming? Why python? One of your problems is that you are being asked to pick a framework, understand how to use it without having any basic knowledge of how to write a computer program. I'm not a teacher, but personally this seems like a really idiotic way to teach a student to learn how programming works. I think that you should write a text on first term calculus in french, or maybe in chinese. Its a similar problem. You need to learn your topic (calculus, some unknown framework), and then you need to exercise your topic in a foreign language. Anyway, here's a book that might be useful: http://inventwithpython.com/ When (if) you get this done, come back and let us see your program -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Making a pass form cgi => webpy framework
On Tue, Jun 25, 2013 at 2:00 PM, wrote: > 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. > > Good question. Sometimes your way is best. > > The main advantage of using templates is that the template contains > only html (mostly) and the cgi code contains only python (mostly). > > The idea is that you can look at the template and see only the > kind of code (html) that affects how the page looks. With some > template systems you can edit the template files with a html > editor and do the page design visually. Even in a text editor > it is usually easier to see the how the html "works" without > spurious stuff like code. > > And when you look at the cgi code, you see only the Python code > that is needed to get the variable data that is displayed in the > page without the distraction of a lot of html stuff. > -- > http://mail.python.org/mailman/listinfo/python-list > I haven't tried webpy but I have used django. django has a tutorial that takes a couple of hours to set up and go through completely. Its not just reading, its hands on trying out a small website. It gives a very good understanding of what the framework offers, and how difficult (or easy!) it is to use. If webpy has a similar tutorial, I would start there, or try django. After the tutorial, the discussion becomes a lot more concrete and less theoretical as to whether that platform would be helpful -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Limit Lines of Output
On Tue, Jun 25, 2013 at 4:09 PM, Bryan Britten wrote: > Hey, group, quick (I hope) question: > > I've got a simple script that counts the number of words in a data set > (it's more complicated than that, but that's one of the functions), but > there are so many words that the output is too much to see in the command > prompt window. What I'd like to be able to do is incorporate the "More..." > feature that help libraries have, but I have no idea how to do it. I also > don't know if I'm asking the question correctly because a Google search > yielding nothing. > > Any insight would be appreciated. Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > If you are using linux, you should look up the comand 'less'. It allows you to page thru a test file. You can either write your list to a file or pipe it into less (haven't tried that myself) -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Limit Lines of Output
On Tue, Jun 25, 2013 at 4:22 PM, Bryan Britten wrote: > Ah, I always forget to mention my OS on these forums. I'm running Windows. > > -- > http://mail.python.org/mailman/listinfo/python-list > I don't think I fully understand your problem. Why can't you send output to a text file, then use a text editor to view results? -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.
On Fri, Jun 28, 2013 at 2:52 PM, Wayne Werner wrote: > On Fri, 28 Jun 2013, 8 Dihedral wrote: > > KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING >> WAS ASSIMULATED BY THE PYTHON COMMUNITY. >> >> OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING >> ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES, >> OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS. >> > > Best. Post. EVER. > In the 'general' category? or by a 'bot'? > > -W > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.
On Fri, Jun 28, 2013 at 3:22 PM, Joshua Landau wrote: > On 28 June 2013 19:52, Wayne Werner wrote: > > On Fri, 28 Jun 2013, 8 Dihedral wrote: > > > >> KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING > >> WAS ASSIMULATED BY THE PYTHON COMMUNITY. > >> > >> OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING > >> ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES, > >> OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS. > > > > > > Best. Post. EVER. > > Dihedral is the one spammer to this list who I appreciate -- he comes > up with spookily accurate gems one day and then hilarious nonsense the > next. One could with all the spammers were bots - they seem to post > less too. > > Alas, Dihedral is in a class of his own. > -- > http://mail.python.org/mailman/listinfo/python-list > I was under the impression that Dihedral is a bot, not a person. Amusing, none the less -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make a web framework
On Fri, Jun 28, 2013 at 5:00 PM, Giorgos Tzampanakis < [email protected]> wrote: > On 2013-06-27, [email protected] wrote: > > > I've used web frameworks, but I don't know how they work. Is there > > anywhere that I can learn how this all works from scratch? > Although it is dated, there is an Apress book called Pro Django which digs into how Django works underneath the hook. You need to understand Python at more than a basic level to get much out of it. > > Yes, read the source code of a mature framework. > > -- > Real (i.e. statistical) tennis and snooker player rankings and ratings: > http://www.statsfair.com/ > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
python adds an extra half space when reading froma string or list -- back to the question
I copied the original question so that the rant on the other thread
can continue. Let's keep this thread ontopic
number_drawn=()
def load(lot_number,number_drawn):
first=input("enter first lot: ")
last=input("enter last lot: ")
for lot_number in range(first,last):
line_out=str(lot_number)
for count in range(1,5):
number_drawn=raw_input("number: ")
line_out=line_out+(number_drawn)
print line_out
finale_line.append(line_out)
finale_line2=finale_line
load(lot_number,number_drawn)
print finale_line
print(" "*4),
for n in range(1,41):
print n, #this is to produce a line of numbers to compare to
output#
for a in finale_line:
print"\n",
print a[0]," ",
space_count=1
for b in range(1,5):
if int(a[b])<10:
print(" "*(int(a[b])-space_count)),int(a[b]),
space_count=int(a[b])
else:
print(" "*(a[b]-space_count)),a[b],
space_count=a[b]+1
number_drawn=()
def load(lot_number,number_drawn):
first=input("enter first lot: ")
last=input("enter last lot: ")
for lot_number in range(first,last):
line_out=str(lot_number)
for count in range(1,5):
number_drawn=raw_input("number: ")
line_out=line_out+(number_drawn)
print line_out
finale_line.append(line_out)
finale_line2=finale_line
load(lot_number,number_drawn)
print finale_line
print(" "*4),
for n in range(1,41):
print n, #this is to produce a line of numbers to compare to
output#
for a in finale_line:
print"\n",
print a[0]," ",
space_count=1
for b in range(1,5):
if int(a[b])<10:
print(" "*(int(a[b])-space_count)),int(a[b]),
space_count=int(a[b])
else:
print(" "*(a[b]-space_count)),a[b],
space_count=a[b]+1
this generates
enter first lot: 1
enter last lot: 4
number: 2
number: 3
number: 4
number: 5
12345
number: 1
number: 2
number: 3
number: 4
21234
number: 3
number: 4
number: 5
number: 6
33456
['12345', '21234', '33456']
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40
1 2 3 4 5
21 2 3 4
3 3 4 5 6
>#as you can see many numbers are between the lines of a normal print#
#I thought this was due to "white space" int he format .So I tried a list
of strings and got the same results.#
--
Joel Goldstick
http://joelgoldstick.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Geo Location extracted from visitors ip address
On Fri, Jul 5, 2013 at 8:08 PM, Νίκος Gr33k wrote:
> Στις 6/7/2013 2:58 πμ, ο/η Νίκος Gr33k έγραψε:
>
> Στις 6/7/2013 2:55 πμ, ο/η Νίκος Gr33k έγραψε:
>>
>>> Στις 5/7/2013 10:58 μμ, ο/η Tim Chase έγραψε:
>>>
>>>> On 2013-07-05 22:08, Νίκος Gr33k wrote:
>>>>
>>>>> Is there a way to extract out of some environmental variable the
>>>>> Geo location of the user being the city the user visits out website
>>>>> from?
>>>>>
>>>>> Perhaps by utilizing his originated ip address?
>>>>>
>>>>
>>>> Yep. You can get an 11MB database (17MB uncompressed)
>>>>
>>>> http://dev.maxmind.com/geoip/**legacy/downloadable/<http://dev.maxmind.com/geoip/legacy/downloadable/>
>>>>
>>>
>>>
>>> http://pypi.python.org/pypi/**pygeoip/<http://pypi.python.org/pypi/pygeoip/>
>>> # pure Python
>>>>
>>>
>>> Thank you very much Tim.
>>> i am know trying to use it as:
>>>
>>> import pygeoip
>>>
>>> try:
>>>gic = pygeoip.GeoIP('/root/**GeoIPCity.dat')
>>>host = gic.time_zone_by_addr( os.environ['HTTP_CF_**CONNECTING_IP'] )
>>> except Exception as e:
>>>host = repr(e)
>>>
>>> lets hope it will work!
>>>
>>
>> Just my luck again,
>>
>> PermissionError(13, 'Άρνηση πρόσβασης')
>>
>> Άρνηση πρόσβασης = Access Denied
>>
>> Why would that happen?
>>
>
> root@nikos [~]# ls -l GeoLiteCity.dat
> -rw-r--r-- 1 root root 17633968 Jul 3 02:11 GeoLiteCity.dat
> root@nikos [~]# chmod +x GeoLiteCity.dat
> root@nikos [~]# ls -l GeoLiteCity.dat
> -rwxr-xr-x 1 root root 17633968 Jul 3 02:11 GeoLiteCity.dat*
> root@nikos [~]# python
> Python 3.3.2 (default, Jun 3 2013, 16:18:05)
> [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import pygeoip
>
> >>> gic = pygeoip.GeoIP('/root/**GeoIPCity.dat')
> Traceback (most recent call last):
> File "", line 1, in
> File "/usr/local/lib/python3.3/**site-packages/pygeoip-0.2.6-**
> py3.3.egg/pygeoip/__init__.py"**, line 110, in __init__
> self._filehandle = codecs.open(filename, 'rb', ENCODING)
> File "/usr/local/lib/python3.3/**codecs.py", line 884, in open
> file = builtins.open(filename, mode, buffering)
>
Your code is not finding /root/GeoIPCity.dat because your directory has
this file: GeoLiteCity.dat
> FileNotFoundError: [Errno 2] No such file or directory:
> '/root/GeoIPCity.dat'
Aside from that you might have some permission problems since the file is
owned by root. You should go back to old threads where this issue was
explained.
As was also pointed out, you only get information about where your isp is
located. Phones and tablets find location from triangulating cell towers.
I don't think that laptops have that capability, and desktops probably even
less likely.
What is the purpose that you wish to serve. I don't think you've thought
this through.
>
> >>>
>
>
>
> --
> What is now proved was at first only imagined!
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
--
Joel Goldstick
http://joelgoldstick.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Geo Location extracted from visitors ip address
On Fri, Jul 5, 2013 at 9:10 PM, Νίκος Gr33k wrote: > Στις 6/7/2013 3:56 πμ, ο/η Joel Goldstick έγραψε: > >> >> Your code is not finding /root/GeoIPCity.dat because your directory has >> this file: GeoLiteCity.dat >> >> FileNotFoundError: [Errno 2] No such file or directory: >> '/root/GeoIPCity.dat' >> > > My mistake. > Is there a differnce between GeoLiteCity.dat and GeoIPCity.dat > > > Aside from that you might have some permission problems since the file >> is owned by root. >> > > But he cgi scripts when running have full access to the server. > No? or they only have the kind of access that their user has also? > > > > > As was also pointed out, you only get information about where your isp >> is located. >> > Its the best i can get to, since there is no other way to match the users > city. > > Β Phones and tablets find location from triangulating cell > >> towers.Β I don't think that laptops have that capability, and desktops >> probably even less likely. >> > > What do you mean by that? > > > What is the purpose that you wish to serve.Β I don't think you've >> thought this through. >> > > I just dont want to store visitor's ip addresses any more, i prefer to > store its city of origin. > > Except its the ISP city that you are getting, not the user's > > > -- > What is now proved was at first only imagined! > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Geo Location extracted from visitors ip address
On Fri, Jul 5, 2013 at 3:08 PM, Νίκος Gr33k wrote: > Is there a way to extract out of some environmental variable the Geo > location of the user being the city the user visits out website from? > > Perhaps by utilizing his originated ip address? > > -- > What is now proved was at first only imagined! > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > Google shows lots of results. This one might work for you: http://freegeoip.net/ -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: the general development using Python
On Mon, Jul 8, 2013 at 9:45 PM, wrote: > all, > > I am unhappy with the general Python documentation and tutorials. I have > worked with Python very little and I'm well aware of the fact that it is a > lower-level language that integrates with the shell. > > I came from a VB legacy background and I've already "un-learned" > everything that I need to (I know, that language stinks, and isn't OOP or > even useful!). > > I have to get back into writing Python but I'm lacking one thing ... a > general understanding of how to write applications that can be deployed > (either in .exe format or in other formats). > > So my issue is basically to understand how to go about writing programs > and compiling them so they can be deployed to less tech-savvy people. > Here's what I think I have to do, in a general sense: > > => Pick a GUI and just run through the tutorials to learn the interfaces > as fast as possible. > > This is all fine and dandy, but more than likely when I do this the people > that I am sending solutions to will, if not receiving a simple .exe file, > receive the package from me and say to themselves "what in the world do I > do with this!?" > > Is there anyway you guys would suggest that I fix this or help them deal > with complex languages like Python and programs written with it? > > thanks guys. > -- > http://mail.python.org/mailman/listinfo/python-list > Why do you want to use python? It isn't a language that can be packaged as an executable. Who are these people who you make software for who need to have a single file? -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Stack Overflow moderator “animuson”
call your mom On Wed, Jul 10, 2013 at 12:18 PM, Ethan Furman wrote: > On 07/10/2013 08:54 AM, Joshua Landau wrote: > >> On 10 July 2013 10:00, Steven D'Aprano wrote: >> >>> On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote: >>> >>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want >>>> to face the truth. He has deleted all my postings regarding Python >>>> regular expression matching being extremely slow compared to Perl. >>>> >>> >>> That's by design. We don't want to make the same mistake as Perl, where >>> every problem is solved by a regular expression: >>> >>> http://neilk.net/blog/2000/06/**01/abigails-regex-to-test-for-** >>> prime-numbers/<http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/> >>> >>> so we deliberately make regexes as slow as possible so that programmers >>> will look for a better way to solve their problem. If you check the >>> source code for the re engine, you'll find that for certain regexes, it >>> busy-waits for anything up to 30 seconds at a time, deliberately wasting >>> cycles. >>> >> >> I hate to sound like this but do you realise that this is exactly what >> you're arguing for when saying that sum() shouldn't use "+="? >> > > my_obj = SomeKoolClass() > my_obj.modify_in_some_kool_**way() > new_result = sum([SKC1, SKC2, SKC3], my_obj) > > Guess what? You've just changed my_obj. > > -- > ~Ethan~ > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF-EBCDIC encoding?
On Fri, Jul 12, 2013 at 2:11 PM, Wayne Werner wrote: > Is anyone aware of a UTF-EBCDIC[1] decoder? > > While Python does have a few EBCDIC dialects in the codecs, it does not > have the (relatively new?) UTF-EBCDIC one. > > Additionally, if anyone is aware of a Python tool that can unpack a > mainframe PDS file, that would also be worthwhile. > > > Thanks, > Wayne > > [1]: > https://en.wikipedia.org/wiki/**UTF-EBCDIC<https://en.wikipedia.org/wiki/UTF-EBCDIC> > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > I can't help you. I'm astonished. Trying to imagine the work environment where this technology would be necessary -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF-EBCDIC encoding?
On Fri, Jul 12, 2013 at 3:12 PM, Skip Montanaro wrote: > > I can't help you. I'm astonished. Trying to imagine the work > environment > > where this technology would be necessary > > http://www.iseriespython.com/app/ispMain.py/Start?job=Home > > Skip > I remember the AS400 series.. although I never worked with one. What kind of business still use that stuff? Is it for large corporation accounting, MIS stuff? -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On Fri, Jul 12, 2013 at 11:52 AM, Νικόλας wrote: > Στις 12/7/2013 6:32 μμ, ο/η Dave Angel έγραψε: > > >> I suggest you read that geoiptool site, in particular the page >> >> http://www.geoiptool.com/en/**ip_info/<http://www.geoiptool.com/en/ip_info/> >> >> There is some misinformation, but notice carefully the part about >> dynamic IP addresses. Probably 99% of the individual users on the web >> (the ones using a browser) have dynamic IP addresses. The fixed ones >> are needed by servers, and especially for DNS use, where the name lookup >> wants to be stable for relatively log periods of time. >> > > > I did, for me it gives exact city location and not the ISP's city location. > > I dont know whay for you ti just says Kansas, it shoudln't, since it > susing longitute and latitude, it should have been accurate. > > > Nikos, this is the point where you (again) loose credibility on this list. You asked this question about how to find the location where someone is browsing your site from. You got several answers. The bottom line is that you can't know that location unless the browsing machine does its own geo location (think cell phones) or the user has provided his location via some form. So, now, a week or two later you come back with the same question, as if it hasn't already been answered -- but you give it a 'red herring' kind of twist. As I understand it, you found a new module that you think will do something that all parties answering this question before explained that this is not possible. And you switch up to say "why can't I load this thing?". Well, I don't why you can't load it, but I don't want to help because it doesn't help you solve your stated problem. Your stated problem is done. move on. > -- > What is now proved was at first only imagined! > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Understanding other people's code
On Fri, Jul 12, 2013 at 6:11 PM, Terry Reedy wrote: > On 7/12/2013 10:22 AM, L O'Shea wrote: > >> Hi all, I've been asked to take over a project from someone else and >> to extend the functionality of this. The project is written in Python >> which I haven't had any real experience with (although I do really >> like it) so I've spent the last week or two settling in, trying to >> get my head around Python and the way in which this code works. >> > > If the functions are not documented in prose, is there a test suite that > you can dive into? > > > -- > Terry Jan Reedy > > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > I'm very appreciative of pydoc. -- even for code I write myself!. Learn about it and redirect its output to files, so you can print out all of your modules. (well -- my suggestion!). For the functions and classes that are lacking docstrings, review them and see if you can figure out what they do. Add docstrings.. Not to disrespect this original coder in the slightest, but my work experience has been involved in reading and fixing or updating lots of other peoples code -- most less documented than would be nice. So my def of good code is code with good descriptive docstrings -- at the top level even before documenting the details. Its nice to know where the developer's head was at when the system was put together. -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Ideal way to separate GUI and logic?
On Sun, Jul 14, 2013 at 8:25 PM, wrote: > Thanks for all the responses! > > So as a general idea, I should at the very least separate the GUI from the > program logic by defining the logic as a function, correct? And the next > level of separation is to define the logic as a class in one or more > separate files, and then import it to the file with the GUI, correct? > > My next question is, to what degree should I 'slice' my logic into > functions? How small or how large should one function be, as a rule of > thumb? > -- > http://mail.python.org/mailman/listinfo/python-list > Others may differ. I think you should just write the code. In actually doing that you will learn the pitfalls of how you have divided up your logic. Writing code isn't all theory. It takes practice, and since the days of The Mythical Man-Month, it has been well understood that you always end up throwing away the first system anyway. It has to be built to truly understand what you think you want to create, but in the learning, you realize that its easier and better to start more or less from scratch rather than try to fix the first concept. -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On Fri, Jul 12, 2013 at 7:04 PM, Dennis Lee Bieber wrote: > On Sat, 13 Jul 2013 02:47:38 +1000, Chris Angelico > declaimed the following: > > > > >Oh, and just for laughs, I tried a few of my recent mobile IP > >addresses in the GeoIP lookup. All of them quoted Melbourne someplace, > >some in the CBD and some out in the suburbs, but all vastly wrong, and > >places I haven't been. But I'd never expect it to be accurate on > >those. > > > Well... the MaxMind demo of "my IP" did get the proper metropolitan > area... But they list the ISP as "AT&T"... My real ISP is Earthlink > (piggybacking on AT&T DSL service). > > The Lat/Long, however shows as > > 42.9634 -85.6681 > whereas a recent GPS readout shows > 42.9159 -85.5541 > > or 2m50s too far north, and 6m50s too far west. > > Same website, accessed from my Blackberry phone, gave a result of > "United States, NA" and location 38 -97 > -- > Wulfraed Dennis Lee Bieber AF6VN > [email protected]://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > Speaking more from a political perspective, an important aspect of the internet is that if you are a publisher who doesn't require registration to read what you post, your readers are free to be more or less anonymous. This is a good thing in many ways. If you have a service that requires some sort of sign up, then you can require knowing things about them (location, etc). If you want to know where your readers are, you need to make arrangements with their ISPs to get that information, since in many cases the ISP has a physical link to your machine. But why should they provide that to you? After all you are not their customer. It might be fun to know, but the repercussions are serious. -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Dihedral
On Mon, Jul 15, 2013 at 8:52 AM, Devyn Collier Johnson < [email protected]> wrote: > > On 07/15/2013 08:36 AM, Steven D'Aprano wrote: > >> On Mon, 15 Jul 2013 06:06:06 -0400, Devyn Collier Johnson wrote: >> >> On 07/14/2013 02:17 PM, 8 Dihedral wrote: >>> >> [...] >> >>> Do we want volunteers to speed up >>>> search operations in the string module in Python? >>>> >>> It would be nice if someone could speed it up. >>> >> Devyn, >> >> 8 Dihedral is our resident bot, not a human being. Nobody knows who >> controls it, and why they are running it, but we are pretty certain that >> it is a bot responding mechanically to keywords in people's posts. >> >> It's a very clever bot, but still a bot. About one post in four is >> meaningless jargon, the other three are relevant enough to fool people >> into thinking that maybe it is a human being. It had me fooled for a long >> time. >> >> >> >> Wow! Our mailing list has a pet bot. I bet other mailing lists are so > jealous of us. Who ever created Dihedral is a genius! > > Artificial Intelligence developers put chatbots on mailing lists so that > the program can learn. I use Python3 to program AI applications. If you see > my Launchpad account, you will see my two AI projects - Neobot and Novabot. > (https://launchpad.net/neobot Neo and Nova are still unstable) AI > developers let their bots loose on the Internet to learn from people. > Dihedral is learning from us. Dihedral only responses when it feels it has > sufficient knowledge on the topic. Chatbots want to appear human. That is > their goal. We should feel honored that Dihedral's botmaster feels that > this mailinglist would benefit the development of Dihedral's knowledge. > > Devyn Collier Johnson > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > I particularly enjoy the misspellings, that seem to be such a human quality on email messages! -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On Tue, Jul 16, 2013 at 3:43 PM, Νικόλας wrote: > Στις 14/7/2013 1:57 πμ, ο/η Michael Torrie έγραψε: > >> 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://diveintohtml5.info/geolocation.html> >> >> > Lest say i embed inside my index.html the Javascript Geo Code. > > Is there a way to pass Javascript's outcome to my Python cgi script > somehow? > > Can Javascript and Python Cgi somehow exchnage data? > > -- > What is now proved was at first only imagined! > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > Learn about ajax -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Homework help requested (not what you think!)
On Tue, Jul 16, 2013 at 8:40 PM, Chris Angelico wrote:
> On Wed, Jul 17, 2013 at 8:43 AM, John Ladasky
> wrote:
> > I think that they're disappointed when I show them how much they have to
> understand just to write a program that plays Tic Tac Toe.
>
>
> The disillusionment of every novice programmer, I think. It starts out
> as "I want to learn programming and make a game". Real programming is
> more like "I can automate mundane tasks", which doesn't sound half as
> exciting. But this is why I'm dubious of programming courses that
> actually try to hold onto the "let's make a game" concept, because the
> students are likely to get a bit of a let-down on realizing that it
> really doesn't work that easily ("this is a two-week course, at the
> end of it I should have written the next
> for all my friends").
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
There is a book : http://inventwithpython.com/ *Invent Your Own Computer
Games with Python*
which claims to teach people to program games in python. I haven't read
it, but it seems to be for beginning programmers. Take a look.. Maybe it
would work for your kids. It says its for kids younger than high school,
but it claims to be for all ages. It does cover the turf your gang seems
most interested in. Other positives -- its free online. so no
investment. And it introduces the concept of open source which is really a
key to a large segment of the whole software world, so that gives another
teaching moment
--
Joel Goldstick
http://joelgoldstick.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python HTTP POST
On Wed, Jul 17, 2013 at 4:15 PM, John Gordon wrote: > In <[email protected]> Matt Graves < > [email protected]> writes: > > > How would I submit a python HTTP POST request to... for example, go to > > google.com, enter "Pie" into the search box and submit (Search) > > Something like this: > > import urllib > import urllib2 > > # the google form search input box is named 'q' > data = { 'q': 'Pie' } > > response = urllib2.urlopen('http://google.com', urllib.urlencode(data)) > print response.read() > > -- > John Gordon A is for Amy, who fell down the stairs > [email protected] B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > Many people find urllib and urllib2 to be confusing. There is a module called requests which makes this stuff a lot easier. ymmv http://docs.python-requests.org/en/latest/ -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Share Code Tips
On Fri, Jul 19, 2013 at 9:51 AM, Devyn Collier Johnson < [email protected]> wrote: > Aloha Python Users! > > I have some coding tips and interesting functions that I want to share > with all of you. I want to give other programmers ideas and inspiration. It > is all Python3; most of it should work in Python2. I am a Unix/Linux > person, so some of these will only work on Unix systems. Sorry Microsuck > users :-D ;-) > > All of the below Python3 code came from Neobot v0.8dev. I host an > artificial intelligence program on Launchpad (LP Username: > devyncjohnson-d). I have not released my Python version yet. The current > version of Neobot (v0.7a) is written in BASH and Python3. > > To emulate the Linux shell's date command, use this Python > > function def DATE(): print(time.strftime("%a %B %d %H:%M:%S %Z %Y")) > > Want an easy way to clear the terminal screen? Then try this: > > def clr(): os.system(['clear','cls'][os.**name <http://os.name> == 'nt']) > > Here are two Linux-only functions: > > def GETRAM(): print(linecache.getline('/**proc/meminfo', > 1).replace('MemTotal:', '').strip()) #Get Total RAM in kilobytes# > def KDE_VERSION(): print(subprocess.getoutput('**kded4 --version | awk > -F: \'NR == 2 {print $2}\'').strip()) ##Get KDE version## > > Need a case-insensitive if-statement? Check this out: > > if 'YOUR_STRING'.lower() in SOMEVAR.lower(): > > Have a Python XML browser and want to add awesome tags? This code would > see if the code to be parsed contains chess tags. If so, then they are > replaced with chess symbols. I know, many people hate trolls, but trolls > are my best friends. Try this: > > if ' re.sub('', '♔', PTRNPRS, flags=re.I); DATA = > re.sub('', '♕', DATA, flags=re.I); DATA = > re.sub(''**, '♖', DATA, flags=re.I); DATA = > re.sub(''**, '♗', DATA, flags=re.I); DATA = > re.sub(''**, '♘', DATA, flags=re.I); DATA = > re.sub('', '♙', DATA, flags=re.I); DATA = > re.sub('', '♚', DATA, flags=re.I); DATA = > re.sub('', '♛', DATA, flags=re.I); DATA = > re.sub(''**, '♜', DATA, flags=re.I); DATA = > re.sub(''**, '♝', DATA, flags=re.I); DATA = > re.sub(''**, '♞', DATA, flags=re.I); PTRNPRS = > re.sub('', '♟', DATA, flags=re.I) > > For those of you making scripts to be run in a terminal, try this for a > fancy terminal prompt: > > INPUTTEMP = input('User ≻≻≻') > > > I may share more code later. Tell me what you think of my coding style and > tips. > > > Mahalo, > > Devyn Collier Johnson > [email protected] > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > I'm guessing you may be posting with html. So all your code runs together. -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tick checkboxes with the same name?
On Tue, Jul 23, 2013 at 12:10 AM, wrote:
> I faced a problem: to implement appropriate search program I need to tick few
> checkboxes which turned out to have the same name (name="a",
> id="a1","a2","a3","a4"). Set_input('a', True) does not work (I use Grab
> library), this command leads to the error "checkboxgroup must be set to a
> sequence". I don't understand what the sequence actually is, so I'm stuck
> with how to tick the checkboxes. It would be really great if someone would
> help me with how to handle this question. The code is available here:
> view-source:http://zakupki.gov.ru/pgz/public/action/contracts/search/ext/enter
> --
> http://mail.python.org/mailman/listinfo/python-list
Have you tried a[0], a[1], etc. for the names?
--
Joel Goldstick
http://joelgoldstick.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: import syntax
On Mon, Jul 29, 2013 at 3:48 PM, Devyn Collier Johnson wrote: > The PEP8 recommends importing like this: > > import os > import re > > not like this: > > import os, re > > Why is that? Is there a performance advantage to one of the styles? > > > Mahalo, > > Devyn Collier Johnson > [email protected] > -- > http://mail.python.org/mailman/listinfo/python-list I think its just for clarity -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP8 79 char max
On Mon, Jul 29, 2013 at 3:43 PM, Devyn Collier Johnson wrote: > In Python programming, the PEP8 recommends limiting lines to a maximum of 79 > characters because "There are still many devices around that are limited to > 80 character lines" (http://www.python.org/dev/peps/pep-0008/#code-lay-out). > What devices cannot handle 80 or more characters on a line? well, punch cards ;) Would following > this recommendation improve script performance? Not performance, but human readability > > Mahalo, > > Devyn Collier Johnson > [email protected] > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Script that converts between indentation and curly braces in Python code
On Tue, Jul 30, 2013 at 11:45 PM, Musical Notation wrote: > Is there any script that converts indentation in Python code to curly braces? > The indentation is sometime lost when I copy my code to an application or a > website. I guess you could google that. What do you mean that indentation is 'sometimes' lost when copying. I think you should walk down that path to understand why you are losing your indentation. It could be you are using tabs instead of spaces for indentation. It could also be that you are inserting your code directly into HTML which of course will eat the extra whitespace. That problem can be solved with tags, or maybe even (but I am not sure about that) If you are copying code to a website like stack exchange you need to precede each line of code with (2 I think!) spaces. They use markdown. If you wanted to add in curly braces, I am guesses the only purpose for this would be that you would convert them back to proper indentation in the copied to environment. So then you have to figure out a way to do that. > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Script that converts between indentation and curly braces in Python code
So, why do you want to do this? As has been pointed out, its a difficult and likely sizable task to build such a parser. In the end you get something that isn't a computer language -- even tho it looks like one. And it also is probably just as big a job to convert it back to python. So, what is the point? Pardon me for making assumptions, but this seems to be a variation on the theme of 'I don't like python, it doesn't have curly braces'. So if you need curly braces, you have many other languages to choose from. Python isn't one of them. -- http://mail.python.org/mailman/listinfo/python-list
Re: Diagramming code
On Mon, Jul 16, 2012 at 3:58 AM, Ulrich Eckhardt wrote: > Am 16.07.2012 03:57, schrieb hamilton: > >> OK then, let me ask, how do you guys learn/understand large projects ? > > > 1. Use the program. This gives you an idea what features are there and a bit > how it could be structured. > 2. Build the program, to see what is done to get the program running. This > should give you an idea what pieces there are and where they are [from]. > 3. Read design documentation (which is too often outdated) which should give > you an idea what the intention of the project's structure is. > 4. Read the code documentation (which is hopefully more up to date). This > should give you an idea about responsibilities within the code. > 5. Read the code itself. This can also be done while single-stepping through > it with a debugger, just to see it run. > > Of course there are also secondary resources like developers' and users' > mailinglists, websites, bugtrackers that provide information and help. > > Sometimes, drawing a few diagrams from steps 3 and 4 to document > relationships between things is helpful. IMHO having a text describing the > relationships in prose is superior to that though. In particular a diagram > can't describe the rationale for something, you need prose for that. > > HTH & YMMV > > Uli > -- > http://mail.python.org/mailman/listinfo/python-list Do you know about pydoc? Its a great way to get a handle on your modules. It doesn't make diagrams, but a synopsis of what is in the module. It makes use of docstrings, for the module and each class and function in the module. -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: shutil ignore fails on passing a tuple?
On Thu, Jul 19, 2012 at 12:43 PM, Alex van der Spek wrote:
> This beats me:
>
>>>>
>>>> ipatterns
>
> ('*.txt', '*.hdf', '*.pdf', '*.png')
>>>>
>>>> igf = shutil.ignore_patterns(ipatterns)
>>>> ignorethis = igf(ddftopdir,os.listdir(ddftopdir))
>
>
> Traceback (most recent call last):
> File "", line 1, in
>ignorethis = igf(ddftopdir,os.listdir(ddftopdir))
> File "C:\Python27\lib\shutil.py", line 138, in _ignore_patterns
>ignored_names.extend(fnmatch.filter(names, pattern))
> File "C:\Python27\lib\fnmatch.py", line 49, in filter
>pat=os.path.normcase(pat)
> File "C:\Python27\lib\ntpath.py", line 46, in normcase
>return s.replace("/", "\\").lower()
> AttributeError: 'tuple' object has no attribute 'replace'
What is s? It needs to be a string. If s is a tuple with string
values, you will have to iterate over each to replace. Or I believe
you could use map.
>
>>>> igg = shutil.ignore_patterns('*.txt', '*.hdf', '*.pdf', '*.png')
>>>> ignorethat = igg(ddftopdir, os.listdir(ddftopdir))
>>>> ignorethat
>
> set(['Chi2.png', 'DTSdata.hdf', 'TST.hdf', 'BullNoseDiffs.png',
> 'DTSall.hdf', 'Symmetry.pdf'])
>>>>
>>>>
>
> Why does it fail on passing in a tuple of ignore strings? I thought the ,
> (comma) is pretty much the tuple constructor (if that is the right word).
>
> How can I solve this? Is there a way to convert a tuple of strings in a form
> that will be accepted?
>
> Thank you in advance,
> Alex van der Spek
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
--
Joel Goldstick
--
http://mail.python.org/mailman/listinfo/python-list
Re: from future import pass_function
On Thu, Jul 26, 2012 at 11:21 AM, Steven D'Aprano wrote: > On Thu, 26 Jul 2012 13:45:23 +0200, Ulrich Eckhardt wrote: > >> I didn't say "Pass should be a function!" but asked "What do you >> think?". You are assuming lots of things about my goals and jumping to >> conclusions like that I'm complaining about the stupid Python syntax, >> that I'm a frustrated noob, that I want someone to fix that syntax, but >> that is not the case! I'm engaging in a discussion here exactly in order >> to test the idea I had. > > Fair point. I underestimated you. But go back and re-read your first > post, and see if you can understand *why* I underestimated you. You > really didn't give any sign that you had given this question much > detailed thought. > > Perhaps if you had mentioned that you had not decided whether this was a > good idea and was looking for arguments both for and against, this tone > of this discussion would have been very different. > > > >>> It took me a long time to learn that, for an established language like >>> Python, change is nearly always for the worse, and any change that >>> requires changing existing code better have a very good excuse. >> >> ...so what do you do when you have an idea? You think about it on your >> own, right? I do so, too, but I also engage in discussions with others. >> See? BTW: I think you missed the implications of this thread's topic and >> the snide remark about forcing people to change their code, i.e. that no >> existing code has to change (apart from the Python implementation, of >> course), even if pass was made a function! > > I think that you misunderstand the purpose of from __future__ import. It > is a *temporary* measure, always. Features which are not backward > compatible are FIRST introduced as __future__ features, and THEN a > release or two later, they become mandatory. (Unless they are dropped, > which has not happened yet.) > > There have been seven __future__ features as of Python 3.2: > > absolute_import (enabled in 2.5, mandatory in 2.7) > division (enabled in 2.2, mandatory in 3.0) > generators (enabled in 2.2, mandatory in 2.3) > nested_scopes (enabled in 2.1, mandatory in 2.2) > print_function (enabled in 2.6, mandatory in 3.0) > unicode_literals (enabled in 2.6, mandatory in 3.0) > with_statement (enabled in 2.5, mandatory in 2.6) > > > In any case, I acknowledge that I was wrong about your motivation. I made > a guess based on the limited information I had, and based on my own > history, and you tell me my guess was wrong. I accept that. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list This is the silliest thread I've ever seen in this group. I should abstain, but what the heck: If you want a function that does nothing, write one. Maybe like this: def do_nothing(): return Then, where you previous wrote pass in your code you can replace it with this thing. But really, not being a language meta-maven myself, somewhere above in this thread it was pointed out that pass is a syntax construction that is necessary in the very seldom case where you create a block of code that has no instructions. Instead of braces for every block, you get to skip that in python and just put pass in this extraordinary little case. While I've come to the point in my python coding knowledge to get my day to day work done proficiently, I'm amazed each time I delve deeper into how profoundly well this language was thought out. No offence to all the well meaning participants here, but this looks like trolling -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert base 10 to base 2?
On Mon, Aug 20, 2012 at 1:29 PM, Dennis Lee Bieber
wrote:
> On Mon, 20 Aug 2012 16:52:42 +0200, Jean-Michel Pichavant
> declaimed the following in
> gmane.comp.python.general:
>
>> note that the builtin bin function is not available with python ver < 2.6
>>
>> def Denary2Binary(n):
>> '''convert denary integer n to binary string bStr'''
>> bStr = ''
>> if n < 0: raise ValueError, "must be a positive integer"
>> if n == 0: return '0'
>> while n > 0:
>> bStr = str(n % 2) + bStr
>> n = n >> 1
>> return bStr
>>
>> JM
>>
>> (not my function but I can't remember who I stole from)
>
> I think I typically have done this by going through a hex
> representation.
>
> H2B_Lookup = { "0" : "", "1" : "0001",
> "2" : "0010", "3" : "0011",
> "4" : "0100", "5" : "0101",
> "6" : "0110", "7" : "0111",
> "8" : "1000", "9" : "1001",
> "A" : "1010", "B" : "1011",
> "C" : "1100", "D" : "1101",
> "D" : "1110", "F" : ""}
>
> def I2B(i):
> sgn = " "
> if i < 0:
> sgn = "-"
> i = -i
> h = ("%X" % i)
> return sgn + "".join([H2B_Lookup[c] for c in h])
>
>>>> from i2b import I2B
>>>> I2B(10)
> ' 1010'
>>>> I2B(1238)
> ' 010011100110'
>>>> I2B(-6)
> '-0110'
>>>>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> [email protected]://wlfraed.home.netcom.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
This may be moving off topic, but since you encode -6 as -0110 I
thought I'd chime in on 'two's complement'
with binary number, you can represent 0 to 255 in a byte, or you can
represent numbers from 127 to -128. To get the negative you
complement each bit (0s to 1s, 1s to 0s), then add one to the result.
So:
3 -->0011
~3 -> 11100
add 1 1
result 11101
The nice thing about this representation is that arithmetic works just
fine with a mixture of negative and positive numbers.
eg 8 + (-3) > 1000
11101
gives: 0101
which is 5!
--
Joel Goldstick
--
http://mail.python.org/mailman/listinfo/python-list
Re: help me debug my "word capitalizer" script
On Wed, Aug 22, 2012 at 9:00 AM, Santosh Kumar wrote: > OK! The bug one fixed. Thanks to Andreas Perstinger. > > Let's move to Bug #2: > 2. How do I escape the words that are already in uppercase? For example: > > The input file has this: > NASA > > The script changes this to: > Nasa > > Is it possible to make this script look at a word, see if its first > character is capitalized, if capitalized then skip that word. If not > do the processing? I don't wan to use regex? Do I need it? > -- > http://mail.python.org/mailman/listinfo/python-list Go into your python shell and type help(str) or lookup the documentation on the python site about strings http://docs.python.org/library/string.html There are methods to tell if a word is all caps, or if the first letter is capitalized -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: Objects in Python
On Wed, Aug 22, 2012 at 10:13 AM, shaun wrote: > I'm having an issue its my first time using python and i set up a class one > of the methods is supposed to return a string but instead returns: > > 389E0>> > > Im very new to python and the object orientated feature doesnt seem to be as > well put together as Java. Can anyone help with this problem? > -- > http://mail.python.org/mailman/listinfo/python-list It looks like you didn't add parens to the end of your call. Show us your code. with the traceback -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: writelines puzzle
On Wed, Aug 22, 2012 at 11:38 AM, William R. Wing (Bill Wing) wrote: > In the middle of a longer program that reads and plots data from a log file, > I have added the following five lines (rtt_data is fully qualified file name): > > wd = open(rtt_data, 'w') > stat = wd.write(str(i)) > stat = wd.writelines(str(x_dates[:i])) > stat = wd.writelines(str(y_rtt[:i])) > wd.close() > > The value of i is unknown before I have read through the input log file, but > is typically in the neighborhood of 2500. x_dates is a list of time stamps > from the date2num method, that is values of the form 734716.72445602, day > number plus decimal fraction of a day. y_rtt is a list of three- or > four-digit floating point numbers. The x_dates and y_rtt lists are complete > and plot correctly using matplotlib. Reading and parsing the input log file > and extracting the data I need is time consuming, so I decided to save the > data for further analysis without the overhead of reading and parsing it > every time. > > Much to my surprise, when I looked at the output file, it only contained 160 > characters. Catting produces: > > StraylightPro:Logs wrw$ cat RTT_monitor.dat > 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 > 734737.45097222 734737.45766204][ 240.28.5 73.3 ..., 28.4 27.4 > 26.4] > > Clearly I'm missing something fundamental about using the writelines method, > and I'm sure it will be a DUH moment for me, but I'd sure appreciate someone > telling me how to get that data all written out. I certainly don't insist on > writelines, but I would like the file to be human-readable. > > Python 2.7.3 > OS-X 10.8 > > Thanks, > Bill > -- > http://mail.python.org/mailman/listinfo/python-list writelines writes a list of strings to a file. you are using this: > stat = wd.writelines(str(x_dates[:i])) which is the same as my second line below If you use map it will perform the first argument over the list. See if that works for you >>> l = [1,2,3] >>> str(l) '[1, 2, 3]' >>> s = map(str, l) >>> s ['1', '2', '3'] -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: What do I do to read html files on my pc?
On Mon, Aug 27, 2012 at 9:51 AM, mikcec82 wrote: > Il giorno lunedì 27 agosto 2012 12:59:02 UTC+2, mikcec82 ha scritto: >> Hallo, >> >> >> >> I have an html file on my pc and I want to read it to extract some text. >> >> Can you help on which libs I have to use and how can I do it? >> >> >> >> thank you so much. >> >> >> >> Michele > > Hi ChrisA, Hi Mark. > Thanks a lot. > > I have this html data and I want to check if it is present a string "" > or/and a string "NOT PASSED": > > > > > > > > > > > > > > > . > . > . > > > > > > > CODE CHECK > > > : NOT PASSED > > > > > > Depending on this check I have to fill a cell in an excel file with answer: > NOK (if Not passed or is present), or OK (if Not passed and are not > present). > > Thanks again for your help (and sorry for my english) > -- > http://mail.python.org/mailman/listinfo/python-list from your example it doesn't seem there is enough information to know where in the html your strings will be. If you just read the whole file into a string you can do this: >>> s = "this is a string" >>> if 'this' in s: ... print 'yes' ... yes >>> Of course you will be testing for '' or 'NOT PASSED' -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie ``print`` question
On Sun, Sep 2, 2012 at 1:23 PM, gwhite wrote: > I can't figure out how to stop the "add a space at the beginning" > behavior of the print function. > >>>> print 1,;print 2, > 1 2 > > See the space in between the 1 and the 2 at the output print to the > command console? > > The help for print is: > > "A space is written before each object is (converted and) written, > unless the output system believes it is positioned at the beginning of > a line." > > So it is apparently doing what it is supposed to do. > > Is there a way to stop this? Or is there a different function that > will only print what you have in the formatted string? You can do it with string formatting. My example shows 'old style' string formatting syntax. There is a newer style. You can learn about both from the online python docs. >>> print "%d%d" % (1,2) 12 >>> -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: > A friend made me aware of this: > When a python beginner (2.x) quick searches for "print" on docs.python.org, > the print function doesn't even come up in the top 20 results. > -Dave > -- > http://mail.python.org/mailman/listinfo/python-list That's pretty interesting. I always use google python and get very results. Not a correction for what you think isn't working well on python.org (I think I agree)., but if your friend is looking to learn, my suggestion works great -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting up a class
On Thu, Sep 6, 2012 at 8:00 AM, shaun wrote: > Hi all, > > So I'm trying to to OO a script which is currently in place on work. It > connects to the database and makes multiple strings and sends them to a > server. > > But I'm having major problems since I am new to python I keep trying to do it > as I would do it in Java but classes seem to be very different. I was > wondering could someone answer a few questions? > > 1) Is there anything I should know about passing in variables from another > script to the class? > > 2) When I'm passing variables back to the script they seem to come back blank > as if I haven't done it correctly (I declare the empty variable at the top of > the class, I use the information I get from the database to fill it and I > send it back) Is there anything I'm not doing right with this. > > 3)When I want to use a method from a class in another class method it never > seems to work for me, I have a feeling this is to do with "self" but im not > too sure?? > > Any help would be appreciated. > Thanks, > Shaun > -- > http://mail.python.org/mailman/listinfo/python-list You should take the smallest snippit of your code that shows your problem and copy it here along with traceback where it fails. Java is not python and vice versa, so some of your ideas will be confused for a while -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question About O'Reilly "Python for Unix and Linux System Administration" ftp Mirror question
On Sun, Sep 16, 2012 at 11:09 AM, moonhkt wrote:
> Hi All
>
>
> O'Reilly Book ISBN 978-986-6840-36-4.
>
> python --version
> Python 2.6.2 on AIX 5.3
>
> Using this python to get files in ftp server.
>
> I got below error. What is the error meaning and how to fix ?
>
> ftp_mirror.py
> Traceback (most recent call last):
> File "/xx../shell/ftpmirror.py", line 80, in
> f = FTPSync(options.host, options.username, options.password,
> options.remote_dir, options.local_dir, opti
> ons.delete)
> File "xx../shell/ftpmirror.py", line 17, in __init__
> self.conn.cwd(ftp_base_dir)
> File "/opt/freeware/lib/python2.6/ftplib.py", line 536, in cwd
> cmd = 'CWD ' + dirname
> TypeError: cannot concatenate 'str' and 'NoneType' objects
>
> Source :
>
> #!/usr/bin/env python
>
> import ftplib
> import os
>
> class FTPSync(object):
> def __init__(self, host, username, password, ftp_base_dir,
> local_base_dir, delete=False):
> self.host = host
> self.username = username
> self.password = password
> self.ftp_base_dir = ftp_base_dir
> self.local_base_dir = local_base_dir
> self.delete = delete
>
> self.conn = ftplib.FTP(host, username, password)
> self.conn.cwd(ftp_base_dir)
> try:
> os.makedirs(local_base_dir)
> except OSError:
> pass
> os.chdir(local_base_dir)
> def get_dirs_files(self):
> dir_res = []
> self.conn.dir('.', dir_res.append)
> files = [f.split(None, 8)[-1] for f in dir_res if
> f.startswith('-')]
> dirs = [f.split(None, 8)[-1] for f in dir_res if
> f.startswith('d')]
> return (files, dirs)
> def walk(self, next_dir):
> print "Walking to", next_dir
> self.conn.cwd(next_dir)
> try:
> os.mkdir(next_dir)
> except OSError:
> pass
> os.chdir(next_dir)
>
> ftp_curr_dir = self.conn.pwd()
> local_curr_dir = os.getcwd()
>
> files, dirs = self.get_dirs_files()
> print "FILES:", files
> print "DIRS:", dirs
> for f in files:
> print next_dir, ':', f
> outf = open(f, 'wb')
> try:
> self.conn.retrbinary('RETR %s' % f, outf.write)
> finally:
> outf.close()
> if self.delete:
> print "Deleting", f
> self.conn.delete(f)
> for d in dirs:
> os.chdir(local_curr_dir)
> self.conn.cwd(ftp_curr_dir)
> self.walk(d)
>
> def run(self):
> self.walk('.')
>
>
> if __name__ == '__main__':
> from optparse import OptionParser
> parser = OptionParser()
> parser.add_option("-o", "--host", dest="host",
> action='store', help="FTP host")
> parser.add_option("-u", "--username", dest="username",
> action='store', help="FTP username")
> parser.add_option("-p", "--password", dest="password",
> action='store', help="FTP password")
> parser.add_option("-r", "--remote_dir", dest="remote_dir",
> action='store', help="FTP remote starting directory")
> parser.add_option("-l", "--local_dir", dest="local_dir",
> action='store', help="Local starting directory")
> parser.add_option("-d", "--delete", dest="delete", default=False,
> action='store_true', help="use regex parser")
>
> (options, args) = parser.parse_args()
comment the next line , then print the parameters and see what they
are. That should get you started.
> #f = FTPSync(options.host, options.username, options.password,
> #options.remote_dir, options.local_dir, options.delete)
f = print(options.host, options.username, options.password,
options.remote_dir, options.local_dir, options.delete)
> f.run()
>
> --
> http://mail.python.org/mailman/listinfo/python-list
--
Joel Goldstick
--
http://mail.python.org/mailman/listinfo/python-list
Re: Obnoxious postings from Google Groups (was: datetime issue)
On Sun, Sep 16, 2012 at 11:41 AM, wrote: > Τη Κυριακή, 16 Σεπτεμβρίου 2012 4:18:50 μ.μ. UTC+3, ο χρήστης Ben Finney > έγραψε: >> Νικόλαος Κούρας writes: >> >> >> >> > Iam sorry i didnt do that on purpose and i dont know how this is done. >> >> > >> >> > Iam positng via google groups using chrome, thats all i know. >> >> > > >> >> It is becoming quite clear that some change has happened recently to >> >> Google Groups that makes posts coming from there rather more obnoxious >> >> than before. And there doesn't seem to be much its users can do except >> >> use something else. >> >> >> >> Using Google Groups for posting to Usenet has been a bad idea for a long >> >> time, but now it just seems to be a sure recipe for annoying the rest of >> >> us. Again, not something you have much control over, except to stop >> >> using Google Groups. >> >> >> >> -- >> >> \ “Actually I made up the term “object-oriented”, and I can tell | >> >> `\you I did not have C++ in mind.” —Alan Kay, creator of | >> >> _o__)Smalltalk, at OOPSLA 1997 | >> >> Ben Finney > > > If i ditch google groups what application can i use in Windows 8 to post to > this newsgroup and what newsserver too? > -- > http://mail.python.org/mailman/listinfo/python-list email client to [email protected] -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: Obnoxious postings from Google Groups (was: datetime issue)
On Sun, Sep 16, 2012 at 12:06 PM, wrote: > >> >> > http://mail.python.org/mailman/listinfo/python-list >> >> >> >> email client to [email protected] >> > > wait a minute! i must use my ISP's news server and then post o > comp.lang.python no? > > What is [email protected] how can i post there? > -- > http://mail.python.org/mailman/listinfo/python-list go to the url http://mail.python.org/mailman/listinfo/python-list sign up and use your email client instead. -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: reportlab and python 3
On 2012-09-17 03:47, Laszlo Nagy wrote: Reportlab is on the wall of shame. http://python3wos.appspot.com/ Is there other ways to create PDF files from python 3? There is pyPdf. I haven't tried it yet, but it seem that it is a low level library. It does not handle "flowables" that are automatically split across pages. It does not handle "table headers" that are repeated automatically on the top of every page (when the table does not fit on a page). I need a higher level API, with features compareable to reportlab. Is there such thing? Thanks, Laszlo On 2012-09-17 03:47, Laszlo Nagy wrote: Reportlab is on the wall of shame. http://python3wos.appspot.com/ Is there other ways to create PDF files from python 3? There is pyPdf. I haven't tried it yet, but it seem that it is a low level library. It does not handle "flowables" that are automatically split across pages. It does not handle "table headers" that are repeated automatically on the top of every page (when the table does not fit on a page). I need a higher level API, with features compareable to reportlab. Is there such thing? Thanks, Laszlo I'm afraid that, no, and this is my story of suffering: I been looking for something like that since the past month, first I try to port a library pypdflib[1] with no success, cairo is not well supported yet and the different forks of PIL aren't working nicely with 3.2 also carries a lot of dependencies, so I desist on that. Then I try this pyfpdf [2] to improve another port, but.. I end up spending a LOT of time reading the PDF and PNG SPEC and trying to unphpfy the code (In fact I couldn't make it work png images with alpha mask), so I start to get desperate and I took another approach, wrap another command. First, I try with xhtml2pdf [3], but It does not have a great support for the css rule "@page" which is pretty indispensable for me and in general wasn't very nice to generate precise pdf's, the commercial alternative "prince" have some fame of being good but I'm not willing to spend $3,800 on the license [4], also exists a few other commercial alternatives like pdftron [5] which support python3. And then after all of that my current effort is wrapping FOP [6], but instead of using XSL I reuse mako to generate the fo file, I leverage the pain of writing XML by hand with mako which provides the fo: namespace and some other tricks, at the time it seems robust and feature rich because of the nature of xsl-fo, but who now's I'm just starting with this I'll be working in this approach the following weeks. And if by any mean you found a better alternative please let me know and if you are so kind put the answer in this [7] stackoverflow question. Cheers. [1]: https://github.com/cyraxjoe/pypdflib [2]: https://bitbucket.org/cyraxjoe/py3fpdf [3]: https://github.com/chrisglass/xhtml2pdf [4]: http://www.princexml.com/purchase [5]: http://www.pdftron.com/ [6]: http://xmlgraphics.apache.org/fop/ [7]: http://stackoverflow.com/q/12021216/298371 -- Rivera² -- http://mail.python.org/mailman/listinfo/python-list
Re: Docstring parsing and formatting
On Tue, Sep 18, 2012 at 1:03 AM, Terry Reedy wrote: > On 9/17/2012 10:03 PM, Ben Finney wrote: >> >> Howdy all, >> >> Where can I find a standard implementation of the docstring parsing and >> splitting algorithm from PEP 257? Do you know about pydoc? I haven't looked at its source, but since it does a great job of printing documentation from docstrings it might contain what you need -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: sum works in sequences (Python 3)
On Wed, Sep 19, 2012 at 10:41 AM, Franck Ditter wrote:
> Hello,
> I wonder why sum does not work on the string sequence in Python 3 :
>
>>>> sum((8,5,9,3))
> 25
>>>> sum([5,8,3,9,2])
> 27
>>>> sum('rtarze')
> TypeError: unsupported operand type(s) for +: 'int' and 'str'
>
> I naively thought that sum('abc') would expand to 'a'+'b'+'c'
> And the error message is somewhat cryptic...
>
> franck
> --
> http://mail.python.org/mailman/listinfo/python-list
Help on built-in function sum in module __builtin__:
sum(...)
sum(sequence[, start]) -> value
Returns the sum of a sequence of numbers (NOT strings) plus the value
of parameter 'start' (which defaults to 0). When the sequence is
empty, returns start.
~
--
Joel Goldstick
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to apply the user's HTML environment in a Python programme?
On Fri, Sep 21, 2012 at 8:57 AM, BobAalsma wrote: > I'd like to write a programme that will be offered as a web service (Django), > in which the user will point to a specific URL and the programme will be used > to read the text of that URL. > > This text can be behind a username/password, but for several reasons, I don't > want to know those. > > So I would like to set up a situation where the user logs in (if/when > appropriate), points out the URL to my programme and my programme would then > be able to read that particular text. > > I'm aware this may sound fishy. It should not be: I want the user to be fully > aware and in control of this process. > > Any thoughts on how to approach this? There are several python modules to get web pages. urllib, urllib2 and another called requests. (http://kennethreitz.com/requests-python-http-module.html) Check those out > > Best regards, > Bob > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: How to apply the user's HTML environment in a Python programme?
On Fri, Sep 21, 2012 at 9:58 AM, BobAalsma wrote: > Op vrijdag 21 september 2012 15:36:11 UTC+2 schreef Jerry Hill het volgende: >> On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: >> >> > Thanks, Joel, yes, but as far as I'm aware these would all require the >> > Python programme to have the user's username and password (or >> > "credentials"), which I wanted to avoid. >> >> >> >> No matter what you do, your web service is going to have to >> >> authenticate with the remote web site. The details of that >> >> authentication are going to vary with each remote web site you want to >> >> connect to. >> >> >> >> -- >> >> Jerry > > Hmm, from the previous posts I get the impression that I could best solve > this by asking the user for the specific combination of username, password > and URL + promising not to keep any of that... > > OK, that does sound doable - thank you all I recommend that you write your program to read pages that are not protected. Once you get that working, you can go back and figure out how you want to get the username/password from your 'friends' and add that in. Also look up Beautiful Soup (version 4) for a great library to parse the pages that you retrieve > > Bob > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: Algorithms using Python?
On Fri, Sep 21, 2012 at 4:56 AM, Mayuresh Kathe wrote: > Is there a good book on foundational as well as advanced algorithms using > Python? > > Thanks. > > -- > http://mail.python.org/mailman/listinfo/python-list There is one on Apress that I've seen http://www.amazon.com/Python-Algorithms-Mastering-Language-Experts/dp/1430232374 -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: trying to unsubscribe
On Tue, Oct 2, 2012 at 3:01 PM, timothy holmes wrote: > My efforts at trying to unsubscribe are not working. Could you help me with > this, or take this email as a request to unsubscribe. > Thanks, > Timothy Holmes > > -- > http://mail.python.org/mailman/listinfo/python-list > Go here http://mail.python.org/mailman/listinfo/python-list and look for unsubscribe near the bottom -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print html in python the normal way
On Thu, Oct 4, 2012 at 9:11 AM, Ramchandra Apte wrote:
> On Thursday, 4 October 2012 17:00:57 UTC+5:30, Chris Angelico wrote:
>> On Thu, Oct 4, 2012 at 9:24 PM, wrote:
>>
>> > am I missing something.
>>
>>
You should look at the built in django tags, and learn about them
before writing your own
In this case, look here:
https://docs.djangoproject.com/en/dev/topics/templates/#filters
striptags
Strips all [X]HTML tags. For example:
{{ value|striptags }}
If value is "Joel is a slug",
the output will be "Joel is a slug".
Again, these are just a few examples; see the built-in filter
reference for the complete list.
--
Joel Goldstick
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to create a login screen using core python language without using any framework
On Fri, Oct 5, 2012 at 5:29 AM, Hans Mulder wrote: > On 5/10/12 10:03:56, [email protected] wrote: >> I need to develop a simple login page using Python language with >> two fields and a button, like: >> >> Username, Password, Login >> >> I know there are some beautiful Python frameworks like >> >> Django, Grok, WebPy, TurboGears >> >> which support web development using Python, but mine is a basic >> requirement consisting of only 3 screens (pages): >> >> * 1st page - Login page (Redirects to 2nd page when login button >> is clicked) >> * 2nd page - Page with records in the form of a list, with an >> option for adding new records (Redirects to 3rd page when "Add >> Records" button is clicked) >> * 3rd page - Page with fields, which are saved as records for >> the list on 2nd page (After entering details and clicking Submit) > > Implementing your application using any of those frameworks you > mentioned, would be easy. > >> So, I have decided to develop the above functionality using Python >> **without** using any framework, so that I can have flexibility as >> well as write my own code. > > This is a bad idea. You'll get much more flexibility using > an existing framework then you'd ever achieve by reinventing > the wheel on your own. Especially if you have no experience > in this field. > >> 1. Is it possible to create a login page using Python without >> using a framework? > > Yes. > > But it's a lot of work. You'd effectively be rewriting all > the functionality you'd get for free with a framework. And > it wouldn't be as flexible, because frameworks can flex in > directions that you didn't think of. > >> 2. I haven't worked on web services and don't know the basics of >> web development in Python. > > In that case, your chances of success are fairly slim. > >> 3. If possible, can you provide me an example on how to create a >> login page using Python and achieve the functionality described >> above? > > The frameworks you mentioned earlier come with tutorials. > These tutorials contain such examples. > > You should really use an existing framework. Once you're > aware of how much functionality you get out of a framework > (any of them), you wouldn't dream of rewriting all that > functionality on your own. I totally agree about using a framework. You say you want a 'simple' 3 page website. Why do you think it is simple? You say you don't have any skills at creating websites with python. From your description, you will need to build a directory of entries, a form, and attach it to a database, so that means you also need to understand sql (or something!). You need to display individual records I imagine. Do you need to edit them after they are created? How are you going to manage the accounts? Will you create them? Will you let the visitor create an account? Where will you store the account information? Do different accounts have different permissions? If you install django (for instance), go through the online tutorials in about 2 hours, you could probably build your specification in a day. Even if you have problems there is an active django mailing list to ask specific questions. I haven't tried the other frameworks, but there might be similar help available for them. -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: How to call python script from web.
On Fri, Oct 5, 2012 at 9:59 AM, Mike wrote: > Hi, > > I can call the php script from browser assuming apache web server exists. > > How can I call the python script like php script? > > Any thought? > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list A popular way for apache is to use mod_wsgi. http://code.google.com/p/modwsgi/ -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: how to build Object for List data
On Mon, Oct 8, 2012 at 2:50 PM, Laszlo Nagy wrote: >> >> Seq validation >> 1 Program3,1,3,4 # max(F1,F3) to F4 >> .. >> n >> How to using python to Read the text file, Build the data as object >> class ? > > Open the file using the open() command. Then iterate over the lines within a > stateful algorithm that parses the lines with regular expressions. before you go the regex route try str.split() since it looks like your columns are separated by tabs or spaces. You could also look into csv package. > > What did you try so far? > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on Windows
On Tue, Oct 16, 2012 at 7:29 AM, graham wrote: > > Downloaded and installed Python 2.7.3 for windows (an XP machine). > > Entered the Python interactive interpreter/command line and typed the > following: > > >>>import feedparser > > and I get the error message "No module named feedparser". > > There is a feedparser.py file lurking around - so I suppose Python cannot > find it. > > Anyone: What to do? > > I'm guessing your python path is not set up. Look here: http://docs.python.org/using/windows.html or google windows xp setting python path > > GC > > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: Quickie - Regexp for a string not at the beginning of the line
On Fri, Oct 26, 2012 at 8:32 AM, Ed Morton wrote:
> On 10/25/2012 11:45 PM, Rivka Miller wrote:
>>
>> Thanks everyone, esp this gentleman.
>>
>> The solution that worked best for me is just to use a DOT before the
>> string as the one at the beginning of the line did not have any char
>> before it.
>
>
> That's fine but do you understand that that is not an RE that matches on
> "$hello$ not at the start of a line", it's an RE that matches on " char>$hello$ anywhere in the line"? There's a difference - if you use a tool
> that prints the text that matches an RE then the output if the first RE
> existed would be "$hello$" while the output for the second RE would be
> "X$hello$" or "Y$hello$" or
>
> In some tools you can use /(.)$hello$/ or similar to ignore the first part
> of the RE "(.)" and just print the second "$hello", but that ability and
> it's syntax is tool-specific, you still can't say "here's an RE that does
> this", you've got to say "here's how to find this text using tool
> ".
>
>Ed.
>
>
>> I guess, this requires the ability to ignore the CARAT as the beginning of
>> the line.
>>
>> I am a satisfied custormer. No need for returns. :)
>>
>> On Oct 25, 7:11 pm, Ben Bacarisse wrote:
>>>
>>> Rivka Miller writes:
>>>>
>>>> On Oct 25, 2:27 pm, Danny wrote:
>>>>>
>>>>> Why you just don't give us the string/input, say a line or two, and
>>>>> what you want off of it, so we can tell better what to suggest
>>>
>>>
>>>> no one has really helped yet.
>>>
>>>
>>> Really? I was going to reply but then I saw Janis had given you the
>>> answer. If it's not the answer, you should just reply saying what it is
>>> that's wrong with it.
>>>
>>>> I want to search and modify.
>>>
>>>
>>> Ah. That was missing from the original post. You can't expect people
>>> to help with questions that weren't asked! To replace you will usually
>>> have to capture the single preceding character. E.g. in sed:
>>>
>>>sed -e 's/\(.\)$hello\$/\1XXX/'
>>>
>>> but some RE engines (Perl's, for example) allow you specify zero-width
>>> assertions. You could, in Perl, write
>>>
>>>s/(?<=.)\$hello\$/XXX/
>>>
>>> without having to capture whatever preceded the target string. But
>>> since Perl also has negative zero-width look-behind you can code your
>>> request even more directly:
>>>
>>>s/(?>>
>>>> I dont wanna be tied to a specific language etc so I just want a
>>>> regexp and as many versions as possible. Maybe I should try in emacs
>>>> and so I am now posting to emacs groups also, although javascript has
>>>> rich set of regexp facilities.
>>>
>>>
>>> You can't always have a universal solution because different PE
>>> implementations have different syntax and semantics, but you should be
>>> able to translate Janis's solution of matching *something* before your
>>> target into every RE implementation around.
>>>
>>>> examples
>>>
>>>
>>>> $hello$ should not be selected but
>>>> not hello but all of the $hello$ and $hello$ ... $hello$ each one
>>>> selected
>>>
>>>
>>> I have taken your $s to be literal. That's not 100 obvious since $ is a
>>> common (universal?) RE meta-character.
>>>
>>>
>>> --
>>> Ben.
>>
>>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
I would use str.find('your string')
It returns -1 if not found, and the index if it finds it.
why use regex for this?
--
Joel Goldstick
--
http://mail.python.org/mailman/listinfo/python-list
Re: Difference between range and xrange ??
in python 2.x xrange is a generator and range returns a list. In python 3.x xrange is renamed to range replacing the list function with the generator On Mon, Nov 5, 2012 at 9:23 AM, inshu chauhan wrote: > what is the difference between range and xrange.. both seem to work the > same. ? And which should be used where and in what situations.. ?? > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to creat a func that returns a cursor that can be used?
On Mon, Nov 12, 2012 at 6:01 AM, Chris Angelico wrote:
> On Mon, Nov 12, 2012 at 9:45 PM, Khalid Al-Ghamdi
> wrote:
> > Is there a way to create a func that returns a cursor that can be used
> to execute sql statements?
>
> Yes, and you're almost there!
>
> > I tried this (after importing sqlite3), but it gave me the error below:
> >
> >>>> def connect():
> > return cur
> >>>> connect()
> >
> >>>> cur.execute("select * from schedule")
> > Traceback (most recent call last):
> > File "", line 1, in
> > cur.execute("select * from schedule")
> > NameError: name 'cur' is not defined
>
> All you need to do is make use of the return value. Try this instead:
>
> cur = connect()
>
> That takes the returned cursor object and binds it to the name 'cur'
> in global scope. You can then use 'cur.execute...' and it'll be the
> same object.
>
> As a side point, thank you for posting so clearly. It's easy to help
> when your code and traceback are all there!
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
You asked this question yesterday. I answered as did several others. You
seem to be stuck on how values are returned from a function.
Chris gave you the same help that you got yesterday.
The cur variable within the function disappears when the function ends.
Read about python namespaces to learn more. So, you need to return the cur
value in your function by using this statement:
return cur
Then when you call connect() is will return the cur value. You have to
name it like this:
cur = connect()
You should go to python.org and read the tutorials, specifically about
functions.
good luck
--
Joel Goldstick
--
http://mail.python.org/mailman/listinfo/python-list
Re: Error
On Wed, Nov 14, 2012 at 10:18 AM, inshu chauhan wrote: > > for this code m getting this error : > > CODE : > def ComputeClasses(data): > radius = .5 > points = [] > for cy in xrange(0, data.height): > for cx in xrange(0, data.width): > if data[cy,cx] != (0.0,0.0,0.0): > This code is only run if the test above is true > centre = data[cy, cx] > points.append(centre) > > > change = True > > while change: > > for ring_number in xrange(1, 1000): > change = False > new_indices = GenerateRing(cx, cy, ring_number) > > > for idx in new_indices: > point = data[idx[0], idx[1]] > > if point == (0.0, 0.0, 0.0 ): > continue > else: > dist = distance(centre, point) > centre is only set if the test above is true. In your run, it apparently wasn't > if dist < radius : > print point > points.append(point) > change = True > print change > > > break > > > ERROR : > Traceback (most recent call last): > File "Z:\modules\classification2.py", line 74, in > ComputeClasses(data) > File "Z:\modules\classification2.py", line 56, in ComputeClasses > dist = distance(centre, point) > UnboundLocalError: local variable 'centre' referenced before assignment > > And i am unable to understand .. WHY ? > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: Migrate from Access 2010 / VBA
On Thu, Nov 29, 2012 at 10:43 AM, kagard wrote: > On Nov 27, 7:06 pm, David Bolen wrote: > > kgard writes: > > > I am the lone developer of db apps at a company of 350+ > > > employees. Everything is done in MS Access 2010 and VBA. I'm > > > frustrated with the limitations of this platform and have been > > > considering switching to Python. I've been experimenting with the > > > language for a year or so, and feel comfortable with the basics. > > (...) > > > > -- David > > > > > > Thanks, David, for all the helpful insights. I really appreciate the > time you took to reply. Thanks to everyone who pitched in. You've > given me a lot to think about. > > Keith > -- > http://mail.python.org/mailman/listinfo/python-list > This looks promising: http://www.codediesel.com/data/migrating-access-mdb-to-mysql/ -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: open URL in the current tab
On Mon, Dec 10, 2012 at 5:27 PM, Jabba Laci wrote: > Hi, > > With the webbrowser module you can open a URL in a new tab. But how > could I tell Firefox from Python to open a URL in the _current_ tab? > > The docs say this: webbrowser.open_new(*url*) Open *url* in a new window of the default browser, if possible, otherwise, open *url* in the only browser window. webbrowser.open_new_tab(*url*) Open *url* in a new page (“tab”) of the default browser, if possible, otherwise equivalent to open_new()<http://docs.python.org/2/library/webbrowser.html#webbrowser.open_new> . > Thanks, > > Laszlo > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with print and output to screen
When you read the file line by line the end of line character is included in the result try user[:-1] instead to strip the return from your printed text On Tue, Dec 11, 2012 at 5:31 PM, Mike wrote: > Hello, I am learning python and i have the next problem and i not > understand how fix. > The script is very simple, shows in the terminal the command but, the row > is divided in two: > Example: > > > /opt/zimbra/bin/zmprov ga [email protected] > |egrep > "(zimbraPrefMailForwardingAddress:|zimbraPrefMailForwardingAddress:)" > /opt/zimbra/bin/zmprov ga [email protected] > |egrep > "(zimbraPrefMailForwardingAddress:|zimbraPrefMailForwardingAddress:)" > > And the correct is: > /opt/zimbra/bin/zmprov ga [email protected] |egrep > "(zimbraPrefMailForwardingAddress:|zimbraPrefMailForwardingAddress:)" > > > The script is: > > #!/usr/bin/python > import os > > for user in open ("email"): > print '/opt/zimbra/bin/zmprov ga ' + user + '|egrep > "(zimbraPrefMailForwardingAddress:|zimbraPrefMailForwardingAddress:)" ' > > > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
