Re: Why the nonsense number appears?
Johnny Lee wrote: >Why are there so many nonsense tails? thanks for your help. I guess you were expecting 0.039? You first need to understand floating point numbers: http://docs.python.org/tut/node16.html What you see are the effects of representation errors. The solution is presented here: http://www.python.org/peps/pep-0327.html But briefly, it means your code should read: from decimal import * t1 = "1130748744" t2 = "461" t3 = "1130748744" t4 = "500" time1 = t1+"."+t2 time2 = t3+"."+t4 print time1, time2 Decimal(time2) - Decimal(time1) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python obfuscation
Steve Holden wrote: > Before adding complex protection mechanisms to your code you first need > some code worth protecting, which is to say it should have some novel > features or represent a lot of work that offers useful integrated > functionality for a task or a skill area. > > Most inquiries of this nature appear to fall at that first hurdle. > > There are things you can do, but I'm always keenly aware that very few > users of a program have both the skills and the inclination to rip off > the code even when the source is distributed as part of the product. > Personally I've never bothered with obfuscation, and prefer to rely on > copyright when I deliver code to customers. As you said, if you have some novel features, you will need obfuscation. Copyright doesn't protect the process and patents may take a while. In the meanwhile, good obfuscation is reasonable protection, imho. But I think you failed to note that it may not be a novel feature or useful functionality. In fact, it might be the opposite: a function the users want removed. A typical example would be a shareware registration or nag screen. When the users have to start paying, they might then feel inclied to "rip off the code", or in this case, rip out the code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python obfuscation
Bill Mill wrote: > Your only solution, then, is to write unpopular code. Because, as Alex > said, it will otherwise be broken into. Let's look at two very popular > pieces of code: Half-Life 2 and Windows XP. How are they secured? > Previous version of these software products used sophisticated > client-side programming to try and be secure, but the security was > nonexistant. Users share keys and cracks with each other. and Mike Meyer wrote: > What makes you think this is the case? There are ways to distribute > Python modules so that the user can't just open them in a text > editor. There are also ways to get cryptographic security for > distributed modules. Yes, if you use the same methods you use in C++, > it's "much harder". But by the same token, if you tried to use the > methods you'd use in a Python program in C++, you'd find that the C++ > version was "much harder". > > Of course, as Alex pointed out, all of these are just keeping honest > people honest. The crooks have all the advantages in this game, so you > really can't expect to win. Funny you should mention Half-Life 2. I actually went out and bought Half-Life 2 from the store instead of waiting for a crack to be released (the unique scheme they used meant that crackers will take a little longer than usual). I really wanted to play this game (i.e., it's very popular) and couldn't wait. My brother is bugged by Civilization IV's copy protection. A couple of days ago, after consulting me on what other options he could try, he finally said in frustration, "Maybe I should go buy the game." This is a personal anecdote, but I'm sure it applies to at least some people. Obviously I'm not an honest person. But I'm not so against spending money on software that I won't buy it if there's a pretty good copy protection system on it. The "keeping honest people honest" argument is simplistic and as Ben said, "black and white thinking". Ben's analogy of the house is not a perfect example, but it's still a fair one. You know that if some one really wants to break into your house, he will get in, regardless of your sophisticated laser trip wire system, ex-SAS guards, and genetically-engineered guard dogs. But as long as the cost of protection is less than the cost of the item you're protecting (multiplied by the relevant probabilities, factoring recurring costs, etc), it's worthwhile to spend money on protection. If that fails, then you will of course fall back on the law, but you still try to prevent it from happening in the first place. I do believe that code obfuscation and copy protection measures work, to a limited extent. Few software companies believe that their copy protection will be uncrackable (though their marketing droids may say otherwise), but are most willing to invest in it to at least temporarily stave off the piracy. Distribution of python modules as compiled bytecode is a limited form of obfuscation. Some believe it's enough. But if there's a free obfuscator out there than can increase the difficulty of reverse engineering, why not use that too? Costs you nothing, and may get you a customer or two more before some one manages to crack that. Obfuscation has it's place. It's not the final solution for software protection (and there probably isn't one), but it is one more lock you can use to deter or delay theives. You can't expect to win against determined theives, but you can remove as many advantages that they have. > Now, both of these programs require verification (phone and/or web) to > be used. The only truly secure method of assuring that they're not > used in ways you don't intend is to require the user to contact you to > use it, and that's a deal with the devil. One you might need to make > if security is that important to you, as Microsoft and Valve have > decided it is, but it's a deal with the devil nonetheless. This seems to be opposite to what you said in the previous paragraph. Contacting and verifying with the company every time you use the software is obviously not "the only truly secure method", since there are cracks and keys floating around. It is also not quite as evil as it may seem, since authorization is only required on initial use (and online gaming). -- http://mail.python.org/mailman/listinfo/python-list
Re: Python obfuscation
Alex Martelli wrote:
> It's interesting, in this context, that Civilization IV is mostly
> written in Python (interfaced to some C++ via BoostPython).
>
> It took me 12 seconds with a search engine to determine that CivIV's
> protection uses "SafeDisc 4.60" and 30 more seconds to research that
> issue enough to convince myself that there's enough information out
> there that I could develop a crack for the thing (if I was interested in
> so doing), quite apart from any consideration of the languages and
> libraries used to develop it -- and I'm not even a particularly good
> cracker, nor am I wired into any "underground channels", just looking at
> information easily and openly available out on the web and in the index
> of a major search engine.
Yes, I never said it's uncrackable. The cracks available are iffy and
the alternatives are sufficiently inconvenient to dissuade the
less-savvy user from attempting them. In which case, the copy protection
has succeeded.
> What I think of this thesis is on a par of what I think of this way of
> spelling the possessive adjective "its" (and equally unprintable in
> polite company). If I could choose to eradicate only one of these two
> from the world, I'd opt for the spelling -- the widespread and totally
> unfounded belief in the worth of obfuscation is also damaging, but less
> so, since it only steals some time and energy from developers who (if
> they share this belief) can't be all that good anyway;-).
The level of pedantry here is amazing and it doesn't apply only to
programming languages. While we are discussing my typos, I'd like to
note that I may accidentally interchange "you're" and "your", "there",
"they're", and "their", and a bunch of other homonyms.
I hadn't seen any damage done from misusing "it's". Certainly not on par
with the Sony case which Mike Meyer cites as evidence against copy
protection (and presumably obfuscation, which was the topic of the
discussion)
This topic seems to be drifting. I thought I might clarify what I mean
by "code obfuscation" to get things back on track.
Code obfuscation is a transformation of the program (whether at source
code level, intermediate object code level, binary executable level,
etc) to hinder (prevention seems impossible) reverse engineering
(attempts to determine the workings of the code, to modify the function
of the code, etc). While there are many possible transformations that
can be done on programs (compression, run-time optimizations, etc), the
key here is the intent to hinder reverse engineering. I hope this is
agreeable to everyone.
Python already conveniently supports certain transformations on
programs. Off the top of my head, I think of compiled bytecode (pyc and
pyo files), and modules in zip archives. Any of these can be used as a
means of obfuscation. (Compiled languages naturally undergo
transformations which tend to have more effectiveness against reverse
engineering)
Now, to address points made by Mike Meyer. He says that obfuscation adds
steps to the release process and also cites Sony's XCP fiasco as an
example of unseen costs of "copy protection".
Indeed, everything has a cost, and I was wrong in saying "free".
However, if convenient language-supported transforms are used, the
direct cost of using obfuscation would be miniscule in comparison to
just about everything else. Implementing it should be one simple step,
and testing it shouldn't be required (if you reasonably assume the
language isn't broken).
I am going to ignore certain aspects of the Sony XCP case, such as the
bad EULA and the bad PR (we shall leave that to the lawyers and
marketing folk and stick to something we programmers can actually fix).
What we have left is a broken software implementation of copy
protection. If language-supported (or even OS-supported, which would
have helped Sony*) transformations are used, we can expect to rule out
such brokenness, i.e. no obfuscation-induced incompatibilities and
related help-desk calls. This further reduces the unexpected costs of
code obfuscation to zero (did I miss anything?)
This form of obfuscation is certainly weak, but given that the costs are
so tiny, why not use it? Even if you could gain one customer (and a few
dollars if you're a shareware developer), you have more than recuperated
your costs. If you don't, you probably lost 5 minutes of development
time. Is this a worthwhile gamble? I believe so.
Mike Meyer may reiterate his point about "keeping honest people honest"
and thus such obfuscation has little ("insignificant") benefit. Whether
this little difference is "insignificant" is up to the
developer/publisher/etc to decide. My thesis (to borrow Alex Martelli's
language) is that it is possible to obtain *some* benefit from
obfuscation with *minimal* costs.
There are physical examples of attempts to hinder reverse engineering:
glueing the cases of devices shut and sealing integrated circuits in a
blob of
Re: Python obfuscation
Alex Martelli wrote: > There is no effective manner of protecting your code, except running it > only on well-secured machines you control yourself. If you distribute > your code, in ANY form, and it's at all interesting to people with no > interest in respecting the law, then, it WILL be cracked (and if users > choose to respect the law, then you need no "protecting"). Indeed. An this extends to web services too. If you have input which can be observed (or even better, controlled) and output that can be observed too, one would be able to infer the workings of the code (reverse engineering in one of its purest forms). If your business strategy relies heavily on a proprietary algorithm or even something as weak as lock-in via a proprietary "un-interoperable" data format, then web services is not the final answer. It may work for certain applications (Microsoft's for example) where the cost of reverse engineering is equivalent to the cost of building from scratch. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting dominoes
DaveM wrote: > Essentially, I'm trying to sort 12 dominoes. Each domino has two different > numbers and there are two of every number. Identical dominoes are possible, > but doubles are not. > > The problem is to place the dominoes in a line, side to side, so that two > columns (or rows, depending how you orientate them) are formed, with each > number appearing once in each column(row). > > I thought this would be the easy part of the program I'm writing, but so far > some initial states have defeated every attempt I've made, short of > re-shuffling the dominoes after an arbitrary number of attempts. > > I'm sure I'll work out an effective algorithm eventually, but I suspect I'm > re-inventing the wheel, so any hints on the best way to tackle this would be > appreciated! > > DaveM Assuming your dominoes are expressed as a list of tuples, e.g. [ (1, 2), (3, 2), (3, 1) ]. The pseudo-code would probably be as follows: 1) create a corresponding list of dominoes with each domino reversed 2) concatenate your original list of dominoes with the list of flipped dominoes 3) sort the new concatenated list 4) take every other element in the sorted list, e.g. using [::2] I hadn't actually thought about it enough to verify if it works all the time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Defining functions in an implementation file
westymatt wrote: > I am fairly new to python and I want to put alot of my functions in > another python file and import or from it into my script so I can call > the functions. How is this done? > What you are describing are modules. The Python Tutorial has some information on this http://docs.python.org/tut/node8.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Capturing instant messages
Nick Vatamaniuc wrote: > Assuming a one person per one machine per one chat protocol it might be > possible to recreate the tcp streams (a lot of packet capturing devices > already do that). So the gateway would have to have some kind of a > dispatch that would recognize the initialization of a chat loggon and > start a capture process for each such connection. I imagine with a 1000 > employess he will end up with a 1000 processes running at the same > time. Another way is to capture all the streams at once that deal with > the chat protocol and ports and then replay them later and somehow > cre-create the tcp streams and chat messages in a cron batch job (at > night or weekend). As I said, it's tedious, not impossible. :) The AIM Sniff project (perl, not Python) does most of what you describe, but has bugs because of the approach. You're also ignoring the fact that each person may chat with more than one person. Some protocols route all messages through a central server, making it impossible to use the IP of the other party as a unique identifier (not that it's a good idea to use the IP anyway, since the assumption of one unique and consistent IP per person is weak). Furthermore, you have to deal with failed messages, resends, etc at the application layer. And there are also other non-trivial (but thankfully rarely occurring) issues with TCP stream reconstruction. Basically, it's looking at the wrong OSI layer. An application layer protocol is best handled at the application where all the necessary semantics are easily available. It /is/ an business/organization trying to conform to SOX, so something as minor as switching and standardizing IM clients (not necessarily protocols) would be probably the least of their problems. And probably more manageable than a custom script for a non-trivial activity. There are definitely enterprise solutions available. And if you want to get Python involved in this discussion, consider GAIM, which can be scripted using Python via a plugin. -- http://mail.python.org/mailman/listinfo/python-list
Re: Process files in order
Khoa Nguyen wrote: > I have a requirement to process all files in a directory in > chronological order. The os.listdir() function, however, lists the > files in random order. Is there a similar function in Python that > allows me to specify the listing order (like ls -t for example)? There is no single command, but you can easily sort the results of listdir using any criteria. Most file attributes can can be obtained using os.stat (size, creation date, modification date, etc), and you can just use that as a key to sort(). -- http://mail.python.org/mailman/listinfo/python-list
Re: format a number for output
Tim Williams wrote: a = 1890284 ','.join([str(a)[::-1][x:x+3] for x in range(len(str(a)))[::3]])[::-1] > '1,890,284' > > Ugly ! > >>> b = 189028499 >>> ','.join([str(b)[::-1][x:x+3] for x in range(len(str(b)))[::3]])[::-1] '-,189,028,499' >>> c = 1890284.1 >>> ','.join([str(c)[::-1][x:x+3] for x in range(len(str(c)))[::3]])[::-1] '189,028,4.1' Stick to using locale. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: format a number for output
Yu-Xi Lim wrote: > >>> b = 189028499 > >>> ','.join([str(b)[::-1][x:x+3] for x in range(len(str(b)))[::3]])[::-1] > > '-,189,028,499' Oops, mis-paste >>> b = -189028499 >>> ','.join([str(b)[::-1][x:x+3] for x in range(len(str(b)))[::3]])[::-1] -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
John Salerno wrote: > 1. First of all, does Linux keep track of the packages you manually > install? If so, then I won't have to do this at all. I assume you're using a Debian-based distro with aptitude as the front end. In which case, all dpkg operations should be logged in /var/log/dpkg.log Generally, after the initial installation, all subsequent operations are either updates of existing packages or packages you installed manually. Only rarely do you get new packages installed automatically as a result of an additional dependency from an original automatically installed package. If you know when you completed your initial installation, you can easily parse the log files to determine what else was installed after that. > 2. Assuming I write this, how do output the bash command to the > terminal? Is there a particular module that Python uses to interact with > the terminal window that I can use to send the install command to the > terminal? I'm wondering about the need to "output the bash command to the terminal". It would probably suffice if your Python script just spawned an instance of the shell with the necessary command line. Take a look at the subprocess module. But this really calls for a bash script: #!/bin/bash echo $@ >> /path/to/manual_install.log sudo aptitude install $@ Shorter than the equivalent Python code. You could probably declare this as a function in your bash initialization files too, if you know how to do this. -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
Dennis Lee Bieber wrote: > Well, I don't do shell scripts either, but... looking at the > sample... "$@" is likely the shell equivalent of Python's sys.argv -- or > *sys.argv if passed down Yeah, kinda equivalent to *sys.argv[1:]. -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting a command to the terminal?
Steven Bethard wrote: > import argparse # http://argparse.python-hosting.com/ > import subprocess > import sys Why not the standard lib's optparse? -- http://mail.python.org/mailman/listinfo/python-list
Re: recommended general-purpose string template packages?
Ravi Teja wrote: > Most Python templating engines are general purpose. Choice between them > however is sometimes a matter of preference, like editors. I settled > down on Cheetah for most part. I second Cheetah. It's suitable for most text templates. Many others are specific for XML or HTML documents. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best IDE for Python
Michiel Sikma wrote: > By FOS, do you mean FOSS (Free and Open Source Software)? I've never > seen the acronym FOS used. Maybe he was trying for "Free Open Source IDE" without the semi-redundant "Software" > I personally use Eclipse with PyDev. > http://www.eclipse.org/ > http://pydev.sourceforge.net/ Eclipse+PyDev has the advantage over emacs when it comes to big projects, IMO. It has features like refactoring, better project management, code coverage. emacs has the advantage of being faster and smaller, and if all you need is a syntax-aware (smart indentation, syntax highlighting) editor and integrated debugger, emacs is more than enough. I've tried the other free IDEs like IDLE, SPE, eric3, TruStudio (for Eclipse), Boa, Komodo, WingIDE. I have various issues with them, including instability, poor automatic indentation, bad GUI (too many subwindows or uncustomizable), costly, no refactoring, and no project management. It's strangely ironic. I consider Eclipse to be a lousy Java IDE especially compared to commercial offerings and yet that's what the project started out as. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mega Newbie Questions: Probably FAQs
Zeph wrote: > 1b) Are these executable completely free from the need of the average > user needing to install Python. Basically, I want to write and sell > "compiled" apps. OSX and Linux installations nearly always come with Python pre-installed (usually because they are required by other system software). Your only concern should be the availability of additional Python libraries you may use. > 2) I want a real and native GUI. wxPython or PyQT? My concerns are about > cross-platform and responsiveness of GUI. I suspect that this will be > one of the gravest issues for the long run. Tk is available on all but the most minimalistic of Python distributions. It's also butt-ugly. wxPython is probably a good compromise. > 3) Can someone recommend a good framework that will enable me to keep > things well sorted out, and easy to maintain as my apps grow? (I'm > considering MVC, but have no idea how to apply it until I've gone beyond > "Hello World"). Framework for what kind of apps? Web, native GUI, client-server, etc? MVC is an abstract architecture rather than a specific implementation. Even so, many implementations rarely employ a purely MVC design. > 4) There are a lot of books and tutorials out there, but they are of the > proof-of-concept type. Specifically, a tutorial might teach me Hello > World, but not really care about the framework, because it's a very > simple item, and the point is simply to get me coding. I'd like to start > off with an established, tested and reputable system whose habits I can > ingrain from day one, rather than figure it out later. Can someone > recommend a good book, or your favourite tutorials? Perhaps even one > that assumes MVC as the framework? For GUIs, and wxPython in particular, wxPython in Action would probably be what you have in mind. > 5) Following the above, is there a framework that assumes tcp/ip udp > networking, database connectivity? My first app will be in large part a > networkable database type app where two or more users can share the same > file concurrently. Mix and match. I typically select "best of breed" libraries for the necessary functionality. wxPython for GUI, SQLObject (when it gets too clunky for the regular Python DBAPI), Twisted for networking. > 6) Since I've been a web-developer for a long time (over 10 years), I > never properly learned OOP. Recommended tutorials? OOP is overrated. A multi-paradigm language like Python lets you decide what's best for your particular application. Most Python tutorials would not focus on OOP specifically, unlike Java where you'd have to learn OOP from day 1. OOP may be a suitable model for business logic, but feel free to explore other alternatives for the other parts of your project. But if you insist, try How to Think Like a Computer Scientist (http://www.ibiblio.org/obp/thinkCSpy/). It takes the approach similar to an introductory college-level CS course, which is typically heavy on the OOP and data structures. > 8) Can anyone speak to the point, or point out a useful comparison > between Python and RealBasic? The size of the Python community is huge compared to RealBasic. And you'll benefit from that alone by better answers to your questions, better documentation, and better 3rd party libraries. Side note: You seem like you've researched a bit, but unfortunately been affected by the swirl of buzzwords. While there are usually valid reasons for particular technologies to have so much hype behind them, you should not neglect the alternatives. They may be the answer you seek. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to fill a form
Sulsa wrote: > but i don't know how to post these data if i knew there there would > be no topic. http://docs.python.org/lib/module-urllib.html You want to look at urlopen and urlencode. But if you mean you don't know what fields and data to use, then you need a HTML reference, not a Python one. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tarfile .bz2
Jordan wrote: > So that would explain why a tar.bz2 archive can't be appended to > wouldn't it... And also explain why winrar was so slow to open it (not > something I mentioned before, but definitely noticed). I had wondered > what it was that made bz2 so much better at compression than zip and > rar. Not really on topic anymore but what's the method for tar.gz? And > even more off the topic, does anyone know a good lossless compression > method for images (mainly .jpg and .png)? You can get the same effect from RAR and other formats (ACE, 7z) by using the "Solid Archive" or similar option. Ideally, you'd be compressing lots of similar files for this to be effective. The actual compression ratios of RAR and bz2 can be pretty similar when done this way. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tarfile .bz2
Martin v. Löwis wrote: > Well, .jpg files are already compressed in a lossy way (.jpg is > inherently lossy); to compress it further, you need to increase > the loss. PNG is also compressed already, see Not really. Stuffit has a JPEG compressor which takes advantage of the fact that the JPEG algorithm isn't as optimal as it can be. It converts JPEG images to its own more compact representation which then can be converted back to JPEG as needed, without any loss. It is sadly not free. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing files in a zip to files on drive
kj7ny wrote: > I am attempting to incrementally back up files using python. How can I > compare a file on a hard drive to a file in a python created zip file > to tell if the file has changed? Or should I be using some other > method to determine if a file has changed? > You can easily determine size and date from the hard drive/filesystem and from zip files. Look at the Python docs for the os and zipfile modules. That would be the fastest way to detect changes for most files you will encounter. Zip files have the CRC of each file (generated from the original uncompressed file) for checksumming purposes. You can calculate the CRC for the file on the hard drive and then compare the CRC values. Calculating the CRC should be faster than decompressing the ZIPped file or compressing the file on the hard drive. While not perfect it should definitely give you a very good indication of changed content. Python doesn't any built-in functions for CRC calculations, AFAIK. There are third party modules around. A better plan would be to store a list of MD5 or SHA1 hashes for each file in your archive. These functions are built in to Python and are more suitable for detection large differences in files (these are hash functions while CRC is a checksum function and thus are less likely to have collisions). You can store the list of hashes in a separate file, or as a file in the ZIP file, or even in the ZIP file header. Your last resort would be to decompress each file and compare it with the one on disk. This will take a lot of time and memory. Not at all advisable but definitely foolproof. There are other issues you will have to contend with, such as renaming of files and directories, and deletions. If I were you, I'd take a look at the work done on programs like rsync, unison (both file synchronization programs), or CVS and Subversion (both version or source control programs) to see how they deal with such issues. -- http://mail.python.org/mailman/listinfo/python-list
Re: Screen Scraping Question
jeffbg123 wrote: > The numbers are always rendered the same. So I don't know if OCR is a > necessary step. > > Also, what if I just got the data from the packets? Any disadvantages > to that? Any good python packet capturing libraries? > > Thanks > Packet capture is probably a bad idea for two reasons. 1) It will give you a lot of packets you don't need and at a OSI layer so low that reassembly is painful. Try writing a HTTP or SOCKS proxy and get the Flash game to use that proxy. 2) Many Flash games would probably store (in the Flash file) or generate their scenarios instead of retrieving them over the Internet. -- http://mail.python.org/mailman/listinfo/python-list
Re: Icons for GUI development
Benjamin wrote: > I'm developing a mail client. Since GUI are usually improved with some > icons, I'm looking for some. Because I'm not a very gifted artist I'm > searching for a library of GPL or public domain icons. Any suggestions? > I frequently use the Crystal icon set. http://www.everaldo.com/crystal/ Also, a page of links I encountered recently which may help you: http://www.snap2objects.com/2007/06/06/85-killer-resources-every-designer-should-know/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto Launch a windows application ?
stef mientki wrote:
> cmd =[]
> cmd.append ( 'D:\\PIC-tools\\JALxxx\\jalv2_3.exe' )
> cmd.append ( '-long-start' )
> cmd.append ( '-d')
> cmd.append ( '-clear' )
> cmd.append ( '-sD:\\PIC-tools\\JAL\\libs2' )
> cmd.append (
> 'd:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal' )
> cmd.append ( '>d:\\data_actueel\\d7_test_browser\\temp.log' )
Your problem is probably the last line there with the '>'. That's an
output redirection that is done not by jalv2_3.exe but by the command
shell. That's why it works only with the batch file (which is
interpreted by the command shell.
Using a batch file is probably easiest for this. But I'm guessing you
probably want to change the command line arguments passed to the program
that's why you prefer to build the command line manually.
In that case, there are a few solutions:
1) Generate the batch file programmatically.
2) Use cmd.exe /C (assuming you're on Windows XP). So your program would
be something like:
cmd.append('cmd.exe')
cmd.append('/C')
cmd.append('"D:\\PIC-tools\\JALxxx\\jalv2_3.exe -long-start -d -clear
-sD:\\PIC-tools\\JAL\\libs2
d:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal
>d:\\data_actueel\\d7_test_browser\\temp.log"')
(or something like that)
3) Do the redirection yourself. Remove the line:
cmd.append ('>d:\\data_actueel\\d7_test_browser\\temp.log' )
and instead read the results directly from the Popen.stdout. You can
then write the output to a file if you want.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Dual Python Installed Environments..
sam wrote: > Hey Diez... > > So you're saying it's as simple as creating an env var, and setting it to > the python version... > > ok.. (and yeah, we're talking fedora) > No, env doesn't create an environment variable. It creates a modified environment. The goal here is to have the proper PATH variable set up. env is the preferred method of invoking the Python (and other) interpreter since it may not always be at /usr/bin/python. In distributions like Fedora, /usr/bin/python is usually a symlink to one of python2.5, python2.4, or python2.3 (or whatever have you), each one corresponding to the appropriate Python version. So you're just running the Python interpreter with the version number you desire directly. Without the version number, you will be using the system default. Thus the actual contents of the script running under Python 2.4 is: #!/usr/bin/env python2.4 print "Hello, World!" -- http://mail.python.org/mailman/listinfo/python-list
Re: Arp request to get MAc Adress with IP address
[EMAIL PROTECTED] wrote: > Hello, > I have a network on same subnet. I have an ip address of a machine. > but i need to get its MAC Adress. > Sendingf ARP request is the way i am taking. > > IS there any other way to get this MAC Adress in python.?? > > Also does python go down to level 2 of TCP/IP model?? > > > Sorry if i am to naive. Just learning python > > thanks > Python's standard libs don't do that, but you can probably work out something with sockets. However, I do recommend you take a look at Scapy, which is just great for network protocol manipulation. http://www.secdev.org/projects/scapy/ I hadn't used it in a while, but when I last tried it, it was very promising. -- http://mail.python.org/mailman/listinfo/python-list
Re: Method needed for skipping lines
Gustaf wrote: > Hi all, > > Just for fun, I'm working on a script to count the number of lines in > source files. Some lines are auto-generated (by the IDE) and shouldn't > be counted. The auto-generated part of files start with "Begin VB.Form" > and end with "End" (first thing on the line). The "End" keyword may > appear inside the auto-generated part, but not at the beginning of the > line. > > I imagine having a flag variable to tell whether you're inside the > auto-generated part, but I wasn't able to figure out exactly how. Here's > the function, without the ability to skip auto-generated code: > > # Count the lines of source code in the file > def count_lines(f): > file = open(f, 'r') > rows = 0 > for line in file: >rows = rows + 1 > return rows > > How would you modify this to exclude lines between "Begin VB.Form" and > "End" as described above? > Gustaf David Mertz's Text Processing in Python might give you some more efficient (and interesting) ways of approaching the problem. http://gnosis.cx/TPiP/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting to an SSH account over a HTTP proxy
Diez B. Roggisch wrote: > BJörn Lindqvist wrote: > >> I want to use Python to connect to a SSH account over a HTTP proxy to >> automate some operations. I thought paramiko would be able to do that, >> but it can not (it seems). >> >> Is there some other Python module that can do what I want? > > Is there anything that can do what you want? Last time I checked there is no > such thing as SSH-over-HTTP. Are you sure that is possible? He's referring to the HTTP CONNECT method, which can tunnel arbitrary TCP connections, not just HTTP. The IETF draft for this is titled "Tunneling TCP based protocols through Web proxy servers". AFAIK, there are no Python modules which support that. The protocol itself is fairly simply though, so it shouldn't be too hard to write your own wrapper or proxy for the client side. Things get a little more complicated if you have to authenticate with the proxy first. -- http://mail.python.org/mailman/listinfo/python-list
Re: AOP and pep 246
Carl Banks wrote: > > AOP is a programming paradigm in the same way indie is a genre of > film. I like your explanation! Heck, if it were more directly Python-related, I'd nominate this line for QOTW. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Extension Building Network
[EMAIL PROTECTED] wrote: > Hi, > > I am trying to get a small group of volunteers together to create > Windows binaries for any Python extension developer that needs them, > much like the package/extension builders who volunteer their time to > create Linux RPMs. > > Mike > It's not entirely clear to me what you're compiling. Most of the modules you have there do not have native code. I'm guessing your main focus is building .exe installers for Windows users. If it's just installers of pure Python code, why the extra effort of using both VS and MingW? AFAIK, they both yield functionally identical results---the exact same .py files get installed. I'm also not sure how big a task this is or the issues involved, but here's my take based on what I've read: Throwing more manpower at the task is not the solution. The actual process can be and SHOULD BE highly automated. All that's needed are a proper distutils script, and proper tests. Both responsibilities should fall on the shoulders of the module authors, though I guess experienced volunteers can help out with the former. If the module is pure Python, there should be little need for testing the installer specifically on Windows. If there's a failure, then the module itself is buggy (e.g. making platform-specific assumptions) or there's similar problem with the install script. For a large number of modules on PyPI, building the installer is trivial (assuming pure Python, and a setup script). Compiling them can be easily automated: 1) check PyPI for updates 2) download the latest update 3) build the .exe 3) upload to a website. All that remains is the need for some hardware (a build farm) and the occasional manual intervention. If I'm not mistaken, distutils can build Windows installers on other platforms. Maybe you could set up a Linux LiveCD with the necessary tools installed and distribute that. Module authors who want to build Windows installers can easily use that CD. Volunteers wanting to help can do so easily without having to repeat the task of setting up the toolchain separately. I've done some work as a port maintainer (aka package maintainer) for FreeBSD. The BSD port system is somewhat closer to PEAK's Easy Install, however binary packages (similar to RPMs or DEBs) are also available. The port maintainer's job is solely to ensure that the Makefile (build script) is working and up to date. The actual testing of the code is done by the authors of the software itself and the port maintainer only ensures that the install script works right. Binary packages are built by an automated system using a cluster of computers for various architectures and supported OS versions. Errors during builds are sent to to port maintainers. A similar system is used for most Linux distributions with a central repository for packages. -- http://mail.python.org/mailman/listinfo/python-list
Re: Populating a dictionary, fast
Steven D'Aprano wrote: > (2) More memory will help avoid paging. If you can't get more memory, try > more virtual memory. It will still be slow, but at least the operating > system doesn't have to try moving blocks around as much. > Based on his previous post, it would seem he has 7GB of RAM (with about 5GB free) and 2GB of swap. I don't think RAM is the issue. Maybe there's something wrong with his specific Python installation. What version is it and was it compiled by him? -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite or xml
Tim Chase wrote: >> how much data is considered to be "large amount"? > > one record > > Unless you really need XML to communicate with some other app via a > predetermined schema, use a database to store and retrieve data. If you > only need to send data to another app via a predetermined schema, use a > database and then offer an "export to XML" functionality. I agree. IMO, XML should be used as a data exchange format, not as database format for databases of *any* length. Though some products/projects may tell you otherwise. I won't limit data exchange to only other apps/programs. One benefit of XML is that it's relatively human readable, so exchanging data directly with humans using XML is probably acceptable, but shouldn't be encouraged. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite or xml
Tim Chase wrote: >> how much data is considered to be "large amount"? > > one record > > Unless you really need XML to communicate with some other app via a > predetermined schema, use a database to store and retrieve data. If you > only need to send data to another app via a predetermined schema, use a > database and then offer an "export to XML" functionality. I agree. IMO, XML should be used as a data exchange format, not as database format for databases of *any* length. Though some products/projects may tell you otherwise. I won't limit data exchange to only other apps/programs. One benefit of XML is that it's relatively human readable, so exchanging data directly with humans using XML is probably acceptable, but shouldn't be encouraged. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create graphs an embed them in GUI?
Heiko Niedermeyer wrote: > Sorry for the fuzzy subject... > > Currently I'm writing a little programm to extract some chemical > information out of a text file, and then present it in a pleasant way. > The Extraction works so far, so now the presentation will be next. > If the GUI is only for the graph, try matplotlib. It should do the graphs/charts you require. If necessary, you can combine matplotlib with another GUI toolkit for a full GUI. This might be useful if you want to display menus and dialogs to load the text files, etc. 3D is a different matter. I'd personally go with Python bindings for VTK, but be warned that the learning curve is very steep and the online docs are quite sparse (you're encouraged to buy the book, which is probably the main source of income for the VTK devs). -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create graphs an embed them in GUI?
Heiko Niedermeyer wrote: > Sorry for the fuzzy subject... > > Currently I'm writing a little programm to extract some chemical > information out of a text file, and then present it in a pleasant way. > The Extraction works so far, so now the presentation will be next. > If the GUI is only for the graph, try matplotlib. It should do the graphs/charts you require. If necessary, you can combine matplotlib with another GUI toolkit for a full GUI. This might be useful if you want to display menus and dialogs to load the text files, etc. 3D is a different matter. I'd personally go with Python bindings for VTK, but be warned that the learning curve is very steep and the online docs are quite sparse (you're encouraged to buy the book, which is probably the main source of income for the VTK devs). -- http://mail.python.org/mailman/listinfo/python-list
Re: Core Python Programming . . .
Mike Driscoll wrote: > > 6-11 Conversion. > (a) Create a program that will convert from an integer to an > Internet Protocol (IP) address in the four-octet format of WWW.XXX.YYY.ZZZ > (b) Update your program to be able to do the vice verse of the > above. I think it's is asking to convert a 32-bit int to the dotted form. It's a little known fact, but IP addresses are valid in non-dotted long-int form. Spammers commonly use this trick to disguise their IP addresses in emails from scanners. -- http://mail.python.org/mailman/listinfo/python-list
Re: Core Python Programming . . .
FireNWater wrote: > I guess I'm not fully up to speed on what constitutes an IP address. > Does the term 'octet' refer to an 8-bit (xFF) number? Yes, it somewhat archaic though. It's used when "byte" is ambiguous. On some ancient (by computing standards) computers, the size of a byte may be as small as 6 bits or as big as 9. For the purposes of this question, I think it's safe to assume an IP address is just a 32-bit number. And you need to extract each group of 8-bits and print those out with dots between them. -- http://mail.python.org/mailman/listinfo/python-list
Re: best(fastest) way to send and get lists from files
Abrahams, Max wrote: > I've looked into pickle, dump, load, save, readlines(), etc. > > Which is the best method? Fastest? My lists tend to be around a thousand to a > million items. > > Binary and text files are both okay, text would be preferred in general > unless there's a significant speed boost from something binary. > > thanks 1) Why don't you time them with the timeit module? http://docs.python.org/lib/module-timeit.html Results will vary with the specific data you have, and your hardware speed, but if it's a lot of data, it's most likely going to be the latter that's the bottleneck. A compact binary format will help alleviate this. If you're reading a lot of data into memory, you might have to deal with your OS swap/virtual memory. 2) "Best" depends on what your data is and what you're doing with it. Are you reinventing a flat-file database? There are better solutions for databases. If you're just reformatting data to pass to another program, say, for scientific computation, the portability may be more of an issue. Number crunching the resultant data may be even more time consuming such that the time spent writing/reading it becomes insignificant. -- http://mail.python.org/mailman/listinfo/python-list
Re: image matching algorithms
Daniel Fetchinson wrote: > There are a number of free tools for image matching but it's not very > easy to decipher the actual algorithm from the code that includes db > management, GUI, etc, etc. I have my own image database and GUI so all > I need is the actual algorithm preferably in pseudo code and not in > the form of a research paper (from which I also found a lot but since > I'm not that much interested in the actual science of image > recognition this seems like an over kill). I'd recommend SIFT. There's quite a bit of information on SIFT. In most cases, they don't cover the background science too much, but are still heavy on the math. Pseudo code is hard to come by since it will take many lines of pseudo code just to express one concise mathematical equation. There are however many links to implementations in various languages on the Wikipedia page. http://en.wikipedia.org/wiki/Scale-invariant_feature_transform I have had good experiences with SIFT for feature extraction from images (I have used it for panorama stitching and robot mapping). It's insensitive to scale and rotation. Note that it is a patented algorithm and this may (or may not) pose a problem for you. -- http://mail.python.org/mailman/listinfo/python-list
Re: image matching algorithms
Daniel Fetchinson wrote: > Thanks for the info! SIFT really looks like a heavy weight solution, > but do you think the whole concept can be simplified if all I needed > was: given a photo, find similar ones? I mean SIFT first detects > objects on the image and find similarities, but I don't need the > detection part at all, all I care about is similarity for the whole > photo. I surely don't understand the big picture fully but just have > the general feeling that SIFT and other expert tools are an overkill > for me and a simplified version would be just as good with a much more > easily comprehensible core algorithm. Please describe the kind of photos you are dealing with. Are they identical photos, in say different formats or with different metadata? Or are they rescaled images? Or maybe they are the same photo cropped differently? SIFT will work in more or less the process you described in your first post. It basically calculates the N sets of numbers for each image, representing the unique features of that image and their relative positions. The rest of the process if up to you. You have to compare the different sets of numbers to find the image with the minimal difference, as opposed to comparing the whole image. -- http://mail.python.org/mailman/listinfo/python-list
Re: image matching algorithms
Daniel Fetchinson wrote: > The photos are just coming straight from my digital camera. Same > format (JPEG), varying size (6-10 megapixel) and I would like to be > able to pick one and then query the database for similar ones. For > example: I pick a photo which is more or less a portrait of someone, > the query should return other photos with more or less portraits. If I > pick a landscape with lot of green and a mountain the query should > result in other nature (mostly green) photos. Something along these > lines, of course the matches won't be perfect because I'm looking for > a simple algorithm, but something along these lines. > Ah. In that case, SIFT isn't for you. SIFT would work well if you have multiple photos of the same object. Say, a building from different angles, or the a vase against different backdrops. If I'm understanding your correctly, what you're attempting here is very general and well into the highly experimental. I've been wishing for such a feature to appear in something like Google Image Search (pick/submit a photo and return similar images found on the web). I'm sure if there's even a practical solution, Google (or MS) would be on it already. The problem is that there isn't really one. Despite what you may see claimed in university press releases and research papers, the current crop of algorithms don't work very well, at least according to my understanding and discussion with researchers in this field. The glowing results tend to be from tests done under ideal conditions and there's no real practical and commercial solution. If you restrict the domain somewhat, there are some solutions, but none trivial. You are probably aware of the face searches available on Google and Live. The histogram approach suggested by Shane Geiger may work for some cases and in fact would work very well for identical resized images. I doubt it will work for the general case. A mountain with a grassy plain at noon has quite a different histogram from one at sunset, and yet both have related content. Manual tagging of the images, a la Flickr, would probably be your best bet. Good luck. -- http://mail.python.org/mailman/listinfo/python-list
Re: image matching algorithms
Daniel Fetchinson wrote: > Since you seem to know quite a bit about this topic, what is your > opinion on the apparently 'generic' algorithm described here: > http://grail.cs.washington.edu/projects/query/ ? > So far it seems to me that it does what I'm asking for, it does even > more because it can take a hand drawn sample image and query the > database for similar photos. > > There is even a python implementation for it here: > http://members.tripod.com/~edcjones/pycode.html > > On the histogram method I agree that it won't work partly because of > what you say and partly because it is terribly slow since it's > comparing every single pixel. I'm hardly the expert and can't answer authoritatively, but here's my 2c. I can't comment as to the actual accuracy of the algorithm, since it will depend on your specific data set (set of photos). The algorithm is sensitive to spatial and luminance information (because of the YIQ colorspace), so there are simple ways in which it will fail. The histogram method uses only color, but has a lot of numbers to compare. You may find the histogram method insensitive to spatial relations (a landscape with the mountain on the left and one with the mountain on the right) compared to the wavelet approach. This is a relatively old paper, and I've seen other more recent image retrieval research using wavelets (some cases using only the high-frequency wavelets for "texture" information instead of the low-frequency ones used by this paper for "shape") and other information retrieval-related research using lossy compressed data as the features. If you have time, you may want to look at other research that cite this particular paper. And just a thought: Instead of merely cutting off at m largest-wavelets, why not apply a quantization matrix to all the values? Let me know how it works out. -- http://mail.python.org/mailman/listinfo/python-list
Re: Freesoftware for auto/intelligent code completing in Python
Ali Servet Dönmez wrote: I tried code come completion options in Emacs for Python, but none of them was satisfactory to me. I'd be glad to hear how did your friend get it work though. Perhaps it would help to say what ways the completion in Emacs was not satisfactory? FWIW, it should be possible to get IPython-type completion in Emacs, but I hadn't managed that yet :( Refactoring, too. Both involve Pymacs but I've had limited success with that. As for PyDev (I know you said "No" to this already), the main problem I have with PyDev/Eclipse is the woefully underpowered editor (compared to Emacs), and poor indentation logic. On the plus side, refactoring works pretty well. So why not PyDev? I'm just wondering, you insist on Free/Libre software solutions, and say the ones you tried don't work for you. Why not "use the source" and fix them so they work your way? ;) To quote you: "how hard it could be be writing a freesoftware which would automatically/intelligently auto complete Python code?" -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Written in C?
Grant Edwards wrote: On 2008-07-21, Dan Upton <[EMAIL PROTECTED]> wrote: REAL WORLD programmers who want to be generally useful go and learn C#. No: Real programmers first eat a quiche and then return to their Pascal programming. Bah, new-fangled languages like Pascal... Real programmers write Fortran. Using punch-cards and paper-tape. Real programmers can edit their programs with a pointy stick and some home-made sticky-tape. Bah. Butterflies! http://xkcd.com/378/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Please, I Have A Question before I get started
Skipper wrote: > Hi All, > > I am going to try and learn Python because I want to write at least > one program to help my disabled son with communitation. > snip > > Can python do this? I realize I am responsible for the menu sets, > pictures attaching sounds etc An interesting project. As Steven mentioned, the GUI toolkits for python (and several other major programming languages such as Java and C) are challenging. I recommend you start with something that is already GUI-oriented that would eliminate a lot of the difficulty of display images, detecting mouse clicks, etc. The first thing that comes to mind would be Powerpoint with some short custom Visual Basic code. Another very easy alternative may be HTML with some basic Javascript. It won't take 10 lines of code if you make some compromises on the presentation but you can't include sound. More complex would be stuff like Flash. All would probably take you less time to learn than Python and a GUI toolkit. -- http://mail.python.org/mailman/listinfo/python-list
Re: in-place string reversal
Sathyaish wrote: >> But what's got that to do with it? Strings are very mutable in C. > > I realized after posting that I'd said something incorrect again. The > concept of "mutability" itself is a high-level concept compared to C. > Memory allocation for strings is expensive because of the way malloc() > works to find a "best-fit" against a "first-fit" in traditional memory > management systems. Because of the performance hit, high level > languages and frameworks, such as the Common Type System of the .NET > Framework for example, considers strings as immutable. That, unlike > Python, doesn't however, make them impossible to modify in-place. > I believe part of the reason for their immutability is so that they can be used as dictionary keys, which is a very common use. -- http://mail.python.org/mailman/listinfo/python-list
Re: To run a python script in all the machines from one server
Nick Craig-Wood wrote: > If these are unix machines then I would use ssh/scp. Even if they are Windows PCs, you could just install cygwin, openssh, and python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Plone or TurboGears for Intranet
[EMAIL PROTECTED] wrote: > Hi all, > > Just wondering which technology would best suit the development of > custom intranets in general, things that may be industry specific would > need to be included (say for an industrial design company the addition > of internal memos and even extrememly business specific apps such as > simple inventory control reporting). The other big issue is ease of > templating as the only Plone examples I've seen have seemed to > basically use the original template or a slightly customised version of > it so I'm wondering whether it would be quicker to build it from the > ground up with TurboGears. > > Any thoughts on the matter are greatly appreciated and any examples of > EITHER used extensively in case studies or the like would be fantastic! > > Thanks in advance! > For custom applications, you'd be better off looking at Plone's underlying Zope app server. As an alternative to TG, you may want to consider Django. Memos and non-database apps would probably be okay with just Plone. In fact, for memos, design notes, developer documentation, you'd be best off considering a collaborative editing solution such as Wiki (of which there are numerous variants in any programming language you want). Though some may suggest a single system to fit all needs, unless you require tight integration (e.g. memos reflect real-time inventory information), you'd probably do well deploying them as separate "best of breed" applications. You can customize the UI to make the differences less apparent. -- http://mail.python.org/mailman/listinfo/python-list
