Re: Split string but ignore quotes
On Sep 29, 5:11 pm, Scooter wrote: > I'm attempting to reformat an apache log file that was written with a > custom output format. I'm attempting to get it to w3c format using a > python script. The problem I'm having is the field-to-field matching. > In my python code I'm using split with spaces as my delimiter. But it > fails when it reaches the user agent because that field itself > contains spaces. But that user agent is enclosed with double quotes. > So is there a way to split on a certain delimiter but not to split > within quoted words. > > i.e. a line might look like > > 2009-09-29 12:00:00 - GET / "Mozilla/4.0 (compatible; MSIE 7.0; > Windows NT 6.0; GTB5; SLCC1; .NET CLR 2.0.50727; Media Center PC > 5.0; .NET CLR 3.0.04506; .NET CLR 3.5.21022)"http://somehost.com200 > 1923 1360 31715 - Best option for you is to use shlex module as Björn said. This is quite a simple question and you would find it on your own for sure if you search python docs a little bit :) -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing your scripts, with plenty of re-use
On Oct 5, 8:29 pm, Robert Kern wrote: > On 2009-10-05 12:42 PM, Buck wrote: > > > > >> With the package layout, you would just do: > > >> from parrot.sleeping import sleeping_in_a_bed > >> from parrot.feeding.eating import eat_cracker > > >> This is really much more straightforward than you are making it out to be. > > > As in the OP, I need things to "Just Work" without installation > > requirements. > > The reason for this is that I'm in a large corporate environment > > servicing many groups with their own custom environments. > > The more ad hoc hacks you use rather than the standard approaches, the harder > it > is going to be for you to support those custom environments. > > > Your solution requires work and knowledge on the user's part, > > *All* solutions require work and knowledge. There is no free lunch. The > advantage of standard Python packages is that they are understood the best and > the most widely. > > > but Stef > > seems to be actually solving the complexity problem. It may seem > > trivial to you, but it's beyond many people's grasp and brings the > > usability and reliability of the system way down. > > > Like Stef, I was unable to grasp how to properly use python packages > > in my environment even after reading the documentation repeatedly over > > the course of several months. > > I do believe that you and Stef are exceptions. The vast majority of Python > users > seem to be able to grasp packages well enough. Well, I started using python many years ago (when there were no packages), so I am used to manage such messy files as described above. But it is true that for building larger solution I always use packages, it just looks better :). So my solution: Packages for job tasks and one big messy folder for my private usage (system administration tasks, automation, etc). > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: WMI remote call in python script to create process on remote windows computer
On Oct 8, 10:22 am, Tim Golden wrote:
> David Jackson wrote:
> > ok, cut and pasted, but changed the username/password to protect the
> > innocent.
> > this is from interactive prompt.
> > let me know if i am still not doing the slashes correctly please.
> > i doubt authentication is the issue.; i can get pid information using
> > WQL queries.
> > objCreateProc.Create expects 4 strings (not objects?), right?
>
> Invoking a method isn't as easy as that, I'm afraid. At
> the risk of being boring, can I ask again why you aren't
> using the wmi module, which solves these problems for
> you?
>
> In short you want to do something like this:
> (simplified for testing purposes to use the local machine)
>
>
> import win32com.client
>
> wmi = win32com.client.GetObject ("winmgmts:")
> win32_process = wmi.Get ("Win32_Process")
> in_parameters = win32_process.Methods_ ("Create").InParameters
> in_parameters.Properties_ ('CommandLine').Value = "notepad.exe"
> result = win32_process.ExecMethod_ ("Create", in_parameters)
>
>
>
> TJG
Good point, I would like just to add this:
wmi = win32com.client.GetObject ("winmgmts:username:passw...@host\
\root\\cimv2")
and it is perfect :)
--
http://mail.python.org/mailman/listinfo/python-list
Re: help to convert c++ fonction in python
On Oct 18, 8:13 am, Toff wrote: > On 18 oct, 02:13, geremy condra wrote: > > > > > On Sat, Oct 17, 2009 at 7:57 PM, David Robinow wrote: > > > On Sat, Oct 17, 2009 at 7:48 PM, geremy condra wrote: > > >> For the love of baby kittens, please, please, please tell me that > > >> you do not believe this securely encrypts your data. > > > Yeah, I think it's pretty good. > > > Can you do better? > > > Trivially. Use AES, 3DES, any standard cryptosystem- there are > > literally dozens of excellent, well-studied implementations in > > both C++ and Python, and hardware implementations on many > > processors. > > > The cipher listed will fall in a single round of chosen plaintext > > attacks or chosen ciphertext attacks, and with a keylength of > > 40 bytes against a message length of 768 will give me roughly > > 19 windows on a single encryption. Frequency analysis is > > therefore going to be extremely profitable, not to mention > > trivially easy. > > > Geremy Condra > > Thanks a lot Tim ! > > @Geremy : > this is not a methode to encrypt data > it is more a methode to encode /decode strings > > for exemple to store passwords that need to be used by others > programs > yes it 's insecure > but there is no secure way to store password that 's need to be > retrieve > > PS : sorry for my english Ok, what about SHA1? yeah, it is one-way cipher, but it is also all you need :). When user inputs the password, password is hashed using SHA1 and compared with already stored hash, if hashes are the same, password is correct. You can use this accross your applications and it will always work the same. (if someone forgets his password you can always use random generator to create new one) -- http://mail.python.org/mailman/listinfo/python-list
Re: DreamPie - The Python shell you've always dreamed about!
On Feb 21, 10:42 am, Noam Yorav-Raphael wrote: > I'm pleased to announce DreamPie 1.0 - a new graphical interactive > Python shell! > > Some highlights: > > * Has whatever you would expect from a graphical Python shell - > attribute completion, tooltips which show how to call functions, > highlighting of matching parentheses, etc. > * Fixes a lot of IDLE nuisances - in DreamPie interrupt always works, > history recall and completion works as expected, etc. > * Results are saved in the Result History. Very good work, Noam, I am looking forward to test this with IronPython :) > * Long output is automatically folded so you can focus on what's > important. > * Jython and IronPython support makes DreamPie a great tool for > exploring Java and .NET classes. > * You can copy any amount of code and immediately execute it, and you > can also copy code you typed interactively into a new file, with the > Copy Code Only command. No tabs are used! > * Free software licensed under GPL version 3. > > Check it out athttp://dreampie.sourceforge.net/and tell me what you > think! > > Have fun, > Noam -- http://mail.python.org/mailman/listinfo/python-list
Re: running a program on many processors
On Mar 8, 1:18 am, Paweł Banyś wrote: > Hello, > > I have already read about Python and multiprocessing which allows using > many processors. The idea is to split a program into separate tasks and > run each of them on a separate processor. However I want to run a Python > program doing a single simple task on many processors so that their > cumulative power is available to the program as if there was one huge > CPU instead of many separate ones. Is it possible? How can it be achieved? > > Best regards, > > Paweł I can suggest you to try some .NET language (like c#, Boo <-- python- like, or maybe even IronPython). Reason is that .NET languages do analyze the code and split them into logical parts that run across threads. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem on socket programming
On Jul 31, 2:37 pm, MalC0de wrote: > no, I disabled my firewall, no problem with even enabled firewall ... > no one can help !? Connection refused... connection was refused by the listening socket, it could also be due to the settings of your service, if it accepts only from localhost to localhost (127.0.0.1 to 127.0.0.1) then other connections will not be granted. Try to find some socket samples on python.org (there are plenty of tip and tricks for using sockets) -- http://mail.python.org/mailman/listinfo/python-list
Re: Run pyc file without specifying python path ?
On Jul 30, 4:47 pm, "Barak, Ron" wrote: > > -Original Message- > > From: Dave Angel [mailto:[email protected]] > > Sent: Thursday, July 30, 2009 16:03 > > To: Barak, Ron > > Cc: 'Dave Angel'; '[email protected]' > > Subject: RE: Run pyc file without specifying python path ? > > > Barak, Ron wrote: > > >> -Original Message- > > >> From: Dave Angel [mailto:[email protected]] > > >> Sent: Wednesday, July 29, 2009 21:05 > > >> To: Barak, Ron > > >> Cc: '[email protected]' > > >> Subject: Re: Run pyc file without specifying python path ? > > > >> Barak, Ron wrote: > > > >>> Hi, > > > >>> I wanted to make a python byte-code file executable, > > > >> expecting to be able to run it without specifying "python" on the > > >> (Linux bash) command line. > > > >>> So, I wrote the following: > > > >>> [r...@vmlinux1 python]# cat test_pyc.py #!/usr/bin/env python > > > >>> print "hello" > > >>> [r...@vmlinux1 python]# > > > >>> and made its pyc file executable: > > > >>> [r...@vmlinux1 python]# ls -ls test_pyc.pyc > > >>> 4 -rwxr-xr-x 1 root root 106 Jul 29 14:22 test_pyc.pyc > > >>> [r...@vmlinux1 python]# > > > >>> So, I see: > > > >>> [r...@vmlinux1 python]# file test_pyc.py* > > >>> test_pyc.py: a python script text executable > > >>> test_pyc.pyc: python 2.3 byte-compiled > > >>> [r...@vmlinux1 python]# > > > >>> If I try to do the following, no problem: > > > >>> [r...@vmlinux1 python]# python test_pyc.pyc hello > > >>> [r...@vmlinux1 python]# > > > >>> However, the following fails: > > > >>> [r...@vmlinux1 python]# ./test_pyc.pyc > > >>> -bash: ./test_pyc.pyc: cannot execute binary file > > >>> [r...@vmlinux1 python]# > > > >>> Is there a way to run a pyc file without specifying the > > > >> python path ? > > > >>> Bye, > > >>> Ron. > > > >> I don't currently run Unix, but I think I know the problem. > > > >> In a text file, the shell examines the first line, and if > > it begins > > >> #! > > >> it's assumed to point to the executable of an interpreter for that > > >> text file. Presumably the same trick doesn't work for a .pyc file. > > > >> Why not write a trivial wrapper.py file, don't compile it, and let > > >> that invoke the main code in the .pyc file? > > > >> Then make wrapper.py executable, and you're ready to go. > > > >> DaveA > > > > Hi Dave, > > > Your solution sort of defeats my intended purpose (sorry > > for not divulging my 'hidden agenda'). > > > I wanted my application to "hide" the fact that it's a > > python script, and look as much as possible like it's a > > compiled program. > > > The reason I don't just give my user a py file, is that I > > don't want a cleaver user to change the innards of the script. > > > On the other hand, I don't want to make a compiled > > (freezed?) version of the application, because it'll grow the > > resulting file significantly, and I don't have the experience > > to know how it will run on different Linuxes. > > > Bye, > > > Ron. > > Hi Dave, > > > Most of the other answers basically paraphrased my suggestion > > of making a wrapper file, not compiling it, and making it > > executable. With that > > approach, the user just types "wrapper.py" on his command line. > > > And wrapper.py only needs two lines, a shebang, and an > > import, no big deal if the user modifies it. The rest of > > your code can be .pyc files. > > > Steven makes some good points. You have to define what level > > of clever you're protecting from. A determined hacker will > > The clever I try to guard against is not at hacker level, just the curios > worker. > > > get in no matter what you do, unless you want to ship the > > program in a proprietary embedded system, encased in epoxy. > > Further, if you have an extension of .py or .pyc, a > > knowledgeable hacker will know it's probably python. > > Granted, but the user will know that from the user manual anyway :-) > > > > > You imply you want it to run unmodifed on multiple unknown > > Linux versions. I think that lets out binfmt solutions. > > Actually, no: I know the set of Linuxes my users are likely to have. > > > That means you need to test and support not only multiple > > Linux implementations, but multiple Python versions, because > > who knows what the user may have installed. I think you need > > to rethink your support strategy. And maybe concentrate on > > being able to detect change, rather than prevent it. > > > DaveA > > Thanks for the helpful suggestions. > Ron. how can a compiled python file (pyc) can defend your code against clever-user? Try command cat "yourcode.pyc" and you will is how "hardly" it can be read or modified :). The most easy way how to distribute such file is with some shell batch containing #!/usr/bin/sh python ./lib/myscript.pyc the topology of the app would be a shell script called simply run, or name of your app and something like that and a folder called lib where your pyc file is stored, just make the script executable (chmod a+x shellfile or chmod 75
Re: An assessment of the Unicode standard
On Aug 30, 2:19 pm, r wrote: > On Aug 29, 11:05 pm, Anny Mous wrote: > (snip) > > > How do we distinguish resume from résumé without accents? > > This is another quirk of some languages that befuddles me. What is > with the ongoing language pronunciation tutorial some languages have > turned into -- French is a good example (*puke*). Do you *really* need > those squiggly lines and cues above letters so you won't forget how to > pronounce a word. Pure ridiculousness! > > > Even when we succeed in banning all languages that can't be written using > > A-Z, what do we do about the vast number of legacy documents? How do we > > write about obsolete English letters like Ð and Þ without Unicode? > > Who gives a fig about obsolete languages, thank god they are dead and > let's move on!! > > > > > > Some may say well how can we possibly force countries/people to speak/ > > > code in a uniform manner? Well that's simple, you just stop supporting > > > their cryptic languages by dumping Unicode and returning to the > > > beautiful ASCII and adopting English as the universal world language. > > > Why English? Well because it is so widely spoken. > > > World population: 6.7 billion > > > Number of native Mandarin speakers: 873 million > > Number of native Hindi speakers: 370 million > > Number of native Spanish speakers: 350 million > > Number of native English speakers: 340 million > > > Total number of Mandarin speakers: 1051 million > > Total number of English speakers: 510 million > > >http://www.vistawide.com/languages/top_30_languages.htm > > I was actually referring to countries where the majority of people > *actually* know what a computer is and how to use it... If there > culture has not caught up with western technology yet they are doomed > to the fate of native American Indians. > > > Whichever way you look at it, we should all convert to Mandarin, not > > English. Looks like we still need Unicode. > > see my last comment > > (snip entertaining assumptions) > > > Yes, because language differences have utterly destroyed us so many times in > > the past! > > > Have you thought about the difference between China, with one culture and > > one spoken language for thousands of years, and Europe, with dozens of > > competing cultures, competing governments, and alternate languages for just > > as long? If multiple languages are so harmful, why was it the British, > > French, Japanese, Russians, Germans, Italians, Austrians, Hungarians and > > Americans who were occupying China during the Opium Wars and the Boxer > > Rebellion, instead of the other way around? > > > Strength comes from diversity, not monoculture. > > No strength comes from superior firepower. The Chinese culture stop > evolving thousands of years ago. Who invented gun powder? Yes the > Chinese and all they could do with it was create fireworks. Europeans > took gun powered and started a revolution that changes the world > forever -- for better and for worse, but that is how advancements > work. It wasn't until western influence came along and finally nudged > china into the 21st century. Europeans seek out technology and aren't > dragged down by an antiquated culture which is good for innovation. If > China with it's huge population thought like a European, they would > rule the earth for 10,000 years. Well, I am from one of the non-English speaking countries (Czech Republic). We were always messed up with windows-1250 or iso-8859-2. Unicode is really great thing for us and for our developers. About the "western" technology made in China and Taiwan... do you really think US are so modern? I can only recommend you to visit Japan :). I also think 26 letters are really limited and English is one of the most limited languages ever. It has too strict syntax. Yeah, it is easy to learn, but not so cool to hear every day. Btw how many foreign languages do you speak? -- http://mail.python.org/mailman/listinfo/python-list
Re: easy question, how to double a variable
On Sep 20, 10:27 pm, daggerdvm wrote: > Write the definition of a function twice , that receives an int > parameter and returns an int that is twice the value of the > parameter. > > how can i do this I will stop this theatre... as you should know, you want your function to make arithmetic operation n*2. Everything you have to do is to define some function with parameter n and make this function to return n*2. If you are not jerk, you can make the whole code you need from the previous sentence :))) -- http://mail.python.org/mailman/listinfo/python-list
