Re: emacs user interface design? a talk by Bret Victor
On Feb 26, 7:01 pm, NanoThermite FBibustards wrote: > @Xah Lee, he only tell one point, fast interpreter avoiding Edit- > Compile-Run cycle, and make it INTERACTIVE, the guy did not teach > nothing of design. The principle was first given by Margaret Hamilton > and Zeldin. > Bret's main point is that creators need immediate feedback. Okay, that's Forth. But he illustrated something else about the Forth way of working. When you try ideas out immediately, you discover things you wouldn't have thought of if you had written the whole program and then worked through debugging and integration. Another point he made is about crusaders (my word), people who see something wrong with the status quo and make it their business to change it based on principle. Chuck wasn't the crusader type (maybe he didn't look good in spandex). -- http://mail.python.org/mailman/listinfo/python-list
Python CPU
Hi All, I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL or Verilog? -Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: invert or reverse a string... warning this is a rant
John Salerno wrote:
> rick wrote:
>> Why can't Python have a reverse() function/method like Ruby?
>
> I'm not steeped enough in daily programming to argue that it isn't
> necessary, but my question is why do you need to reverse strings? Is it
> something that happens often enough to warrant a method for it?
I'm home for lunch so my email addy is different.
No, it doesn't happen very often, but when I need to reverse something
(usually a list or a string). I can never remember right of the top of
my head how to do so in Python. I always have to Google for an answer or
refer back to old code.
IMO, I should be able to intuitively know how to do this. Python is so
user-friendly most every place else... why can it not be so here?
I wrote this so I'll never have to remember this again:
def invert(invertable_object):
try:
print invertable_object[::-1]
return invertable_object[::-1]
except:
print 'Object not invertable'
return 1
invert([1,2,3,4])
invert('string')
invert({1:2, 3:4})
--
http://mail.python.org/mailman/listinfo/python-list
Re: invert or reverse a string... warning this is a rant
Fredrik Lundh wrote:
> rick wrote:
>
>> The Ruby approach makes sense to me as a human being.
>
> do the humans on your planet spend a lot of time reversing strings? it's
> definitely not a very common thing to do over here.
On our planet, we're all dyslexic. We tend to do things 'backwards' so
being able to easily invert what we do helps the people we show the code
to on your planet make sense of it.
>
> anyway, if you do this a lot, why not define a helper function?
>
> def reverse(s):
> return s[::-1]
>
> print reverse("redael ruoy ot em ekat")
Thanks, that's what I ended up doing.
--
http://mail.python.org/mailman/listinfo/python-list
Re: invert or reverse a string... warning this is a rant
Steven D'Aprano wrote: > Gah!!! That's *awful* in so many ways. Thanks... I'm used to hearing encouragement like that. After a while you begin to believe that everything you do will be awful, so why even bother trying? It has been my experience that Python has discouraging forums with someone always calling someone else an idiot or telling them they are awful in some way. I love Python, but the community is way too negative, uptight and generally down on users who do not have PhD's in CS or Math. Do you have children? How would your child feel if he brought you something he had made and you then told him it was awful in *sooo* many ways. How does that reflect on you and the community you represent? Cut people who don't think like you some slack, OK? > (1) The name is bad. "invert" is not the same as "reverse". Here's an > invert: 1/2 = 0.5. Your function falsely claims numbers aren't invertable. Dictionary.com invert = to reverse in position, order, direction, or relationship. It matters not that a sequence is thought of as being from left to right, top to bottom or right to left, does it? Read the sequence as you normally would (however that may be) and then invert it or read it in reverse to begin with. I apologize for bringing this up. Thanks for your time. -- http://mail.python.org/mailman/listinfo/python-list
Re: which "GUI module" you suggest me to use?
ZioMiP wrote: > I know that WxPython work only under Windows WxPython works everywhere for me. I have some screenshots from Windows 98 - Vista, Mac OSX, and Debian GNU/Linux... all running the exact same Python & wxPython code: http://filebox.vt.edu/users/rtilley/public/find_ssns/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Who uses Python?
walterbyrd wrote: > I mean other than sysadmins, programmers, and web-site developers? > Anything else? Finance? Web-analytics? SEO? Digital art? IT Security Analysts use it... see code and screenshots... these are not professional programmers: http://filebox.vt.edu/users/rtilley/public/find_ssns/mac/index.html -- http://mail.python.org/mailman/listinfo/python-list
Learning Basics
So I've been studying python for a few months (it is my first foray
into computer programming) and decided to write my own little simple
journaling program. It's all pretty basic stuff but I decided that I'd
learn more from it if more experienced programmers could offer some
thoughts on how I could do things better.
#simple little journal
from time import asctime
myjournal=file('journal.txt','a+')
formatter="*"*80+"\n"
todaysdate=asctime()
myjournal.write(formatter)
myjournal.write(todaysdate + "\n\n")
loop="set"
while loop!=':a':
loop=raw_input(':')
if loop!=':a':
myjournal.write(loop+"\n")
if loopz==':a':
myjournal.close()
#end of stuff
So I'd appreciate some good feedback or ideas.
--
http://mail.python.org/mailman/listinfo/python-list
catching empty strings (I guess that's what they are)
I've began accepting user input :( in an old program. The input comes from a simple text file where users enter filenames (one per line). What is the appropriate way to handle blank lines that hold whitespace, but not characters? Currently, I'm doing this: for user_file in user_files: # Remove whitespace and make lowercase. file_skip_list.append(user_file.strip().lower()) file_skip_list = list(sets.Set(file_skip_list)) However, if the input file has blank lines in it, I get this in my list: '' (that's two single quotes with noting in between) I thought I could do something like this: if user_file == None: pass Or this: if user_file == '': pass But, these don't work, the '' is still there. Any suggestions are appreciated! Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: catching empty strings (I guess that's what they are)
Diez B. Roggisch wrote: > They are still there because you perform the stripping and lowercasing in > the append-call. Not beforehand. Thank you. I made the changes. It works. -- http://mail.python.org/mailman/listinfo/python-list
execute script in certain directory
When I use idle or a shell to execute a python script, the script executes in the directory it is currently in (in this case, my desktop). However, when using GNOME and right clicking the py script and selecting 'open with python', the execution occurs in my home directory, not my desktop. Is there a way to force py scripts to always run within the directory that they reside in? Thanks Brad /home/brad/Desktop/output - python from shell /home/brad/Desktop/output - python from idle /home/brad/output - python from Gnome 'right click' open with menu -- http://mail.python.org/mailman/listinfo/python-list
Re: Open HTML file in IE
gravey wrote:
> Hello.
>
> Apologies if this is a basic question, but I want to open a HTML
> file from my local drive (is generated by another Python script)
> in Internet Explorer. I've had a look at the webbrowser module and
> this doesn't seem to be what I need. Any help much appreciated.
You may try something like this example:
import time
import win32com.client
wie = win32com.client.Dispatch('InternetExplorer.Application')
# Make IE Window Visible.
wie.Visible = 1
# Open this URL
wie.Navigate('www.your_url.com')
# Print 'Busy' while Busy.
while wie.Busy:
print 'Busy'
# Sleep 2 secs, then go home.
time.sleep(2)
wie.GoHome()
# Sleep 2 secs, then go back.
time.sleep(2)
wie.GoBack()
# Refresh the page
time.sleep(2)
wie.Refresh()
# Close IE Window
time.sleep(2)
wie.Quit()
--
http://mail.python.org/mailman/listinfo/python-list
Re: Deleting files and folders used by other processes on Windows
[EMAIL PROTECTED] wrote: > Hi, > > I have been looking into making my file cleaning script more > intelligent. The goal of the script is to delete everything on a > drive except for a couple of folders which are skipped by the script. > Recently, I noticed that some files where not being deleted because a > process was using them. Try this: try: # Make the file's attributes normal so file can be deleted. win32api.SetFileAttributes(os.path.join(root, f), win32con.FILE_ATTRIBUTE_NORMAL) # HKLM/SYSTEM/CurrentControlSet/Control/Session Manager/PendingFileRenameOperations win32api.MoveFileEx(os.path.join(root, f), None, win32con.MOVEFILE_DELAY_UNTIL_REBOOT) except Exception, e: print e Upon reboot the file will be gone... careful though, this canl delete any Windows system file too. -- http://mail.python.org/mailman/listinfo/python-list
re.compile for names
I am developing a list of 3 character strings like this: and bra cam dom emi mar smi ... The goal of the list is to have enough strings to identify files that may contain the names of people. Missing a name in a file is unacceptable. For example, the string 'mar' would get marc, mark, mary, maria... 'smi' would get smith, smiley, smit, etc. False positives are OK (getting common words instead of people's names is OK). I may end up with a thousand or so of these 3 character strings. Is that too much for an re.compile to handle? Also, is this a bad way to approach this problem? Any ideas for improvement are welcome! I can provide more info off-list for those who would like. Thank you for your time, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: re.compile for names
Marc 'BlackJack' Rintsch wrote: > What about names with letters not in the ASCII range? Like Asian names? The names we encounter are spelled out in English... like Xu, Zu, Li-Cheng, Matsumoto, Wantanabee, etc. So the ASCII approach would still work. I guess. My first thought was to spell out names entirely, but that quickly seemed a bad idea. Doing an re on smith with whitespace boundaries is more accurate than smi w/o, but the volume of names just makes it impossible. And the volume of false positives using only smi makes it somewhat worthless too. It's tough when a problem needs an accurate yet broad solution. Too broad and the results are irrelevant as they'll include so many false positives, too accurate and the results will be missing a few names. It's a no-win :( Thanks for the advice. Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
Alex Martelli wrote: > Most popular, however, is no doubt wxWindows -- > mostly because you can freely use it to develop SW which you plan to > distribute under closed-source licenses, while Qt &c force you to choose > -- either pay, or, if you even distribute your code, it will have to be > under the GPL. I'm not sure how well wxWindows works on Mac nowadays... wx Works great on Macs (10.4 at least, maybe others), Linux and Windows. We've used it for several cross-platform apps that needed GUIs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
[EMAIL PROTECTED] wrote: > Just wondering on what peoples opinions are of the GUIs avaiable for > Python? We have used wxPython with great results. It's cross platform. Can use native OS widgets and is easy to program. Compiles easily to exe binaries for Windows users as well. Best of luck, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
Kevin Walzer wrote: > 2. wxPython is big, harder to learn than Tkinter, but looks good on Mac, > Windows, and *Nix. It will require users to install a lot of extra stuff > (or you'll have to bundle the extra stuff). PyInstaller builds binaries beautifully from raw py source. No need to bundle the wx stuff. I develop on Linux, build on Windows (with PyInstaller) and it works great. The source runs on any platform, the Windows binaries is neat for the point and click users. Brad -- http://mail.python.org/mailman/listinfo/python-list
inet_addr() in Python
Does Python have an equivalent to C's inet_addr()? Thanks, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: inet_addr() in Python
Steve Holden wrote:
> brad wrote:
>> Does Python have an equivalent to C's inet_addr()?
>>
> socket.inet_aton() produces a four-byte string you can pass as a struct
> in_addr, if that's what you are looking for. If you want a number then
> use the struct module to manipulate it further.
>
> >>> s.inet_aton('127.0.0.1')
> '\x7f\x00\x00\x01'
>
> regards
> Steve
Thanks! That works great for my needs. I should have read the socket
documentation more thoroughly.
--
http://mail.python.org/mailman/listinfo/python-list
Re: question about math module notation
Stargaming wrote: > Explicitly converting it to `int` works for me. (Without the 3-digit- > block notation, of course.) Thank you! -- http://mail.python.org/mailman/listinfo/python-list
question about math module notation
How does one make the math module spit out actual values without using engineer or scientific notation? I get this from print math.pow(2,64): 1.84467440737e+19 I want this: 18,446,744,073,709,551,616 I'm lazy... I don't want to convert it manually :) -- http://mail.python.org/mailman/listinfo/python-list
Re: I am giving up perl because of assholes on clpm -- switching to Python
James Stroud wrote: > Midway through a semester in college, after a few days (or was it a few > weeks?) of...well...lets just say I was studying real hard...I got lost > on my way to o-chem and wandered into the interior design department by > accident and found what I like to call "the motherload". No, the girls > definitely weren't doing the sciency stuff back then. But that has been > a few years already, so maybe things have changed. > > James In my experience, things have not changed at most PolySci Universities (Georgia Tech, NC State, Virginia Tech, etc). The Comp Engineering/CS/Math classes are still full of boys. Although there are some girls, but not a lot. If a girl is in the class (and that's a big if) no boy in the classs can focus. She distorts the atmosphere of the entire room (in a good way). She's like a giant, shiny, spherical magnet close to a lot of little, ordinary metal shards. Even when the girl isn't a perfect 10 super model, the guys are still distracted because bathes daily and thus smells good. -- http://mail.python.org/mailman/listinfo/python-list
Re: I am giving up perl because of assholes on clpm -- switching to Python
[EMAIL PROTECTED] wrote: > Python is a better language, with php support, anyway, but I am fed up > with attitudes of comp.lang.perl.misc. Assholes in this newsgroup ruin > Perl experience for everyone. Instead of being helpful, snide remarks, > back-biting, scare tactings, and so on proliferate and self > reinforce. All honest people have left this sad newsgroup. Buy bye, > assholes, I am not going to miss you!!! > > Martha Out of the pan and into the fire. :) Welcome to the world of Ph.D's in Computer Science. You think the Perl guys have attitude, just wait and see what you're in for over here. I think you'll find attitudes in any programming language... just different types. May God have mercy on your soul! You'll be making a similar announcement in a few weeks when you switch to Ruby :) The cold, cruel theoretical, lofty Python will mercilessly crush you :) I'm just joking, OK. -- http://mail.python.org/mailman/listinfo/python-list
Re: question about math module notation
Paul Rubin wrote: > print 2**64 Ah yes, that works too... thanks. I've settled on doing it this way: print int(math.pow(2,64)) I like the added parenthesis :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Directory
Rohan wrote:
> I would like to get a list of sub directories in a directory.
> If I use os.listdir i get a list of directories and files in that .
> i only want the list of directories in a directory and not the files
> in it.
> anyone has an idea regarding this.
How far down do you want to go?
All the way to the bottom:
for root, dirs, files in os.walk('.'):
for d in dirs:
print os.path.join(root, d)
Only your current directory:
x = os.listdir('.')
for item in x:
if os.path.isdir(item):
print item
--
http://mail.python.org/mailman/listinfo/python-list
Re: get directory and file names
Alchemist wrote:
> I am working with Python 2.5 on Windows XP (SP2).
>
> How can I traverse a folder, loop through a list of files and get
> their file name and extension in an elegant, pythonic way?
>
> Thank you.
>
try this:
for root, dirs, files in os.walk('.'):
for f in files:
print os.path.splitext(os.path.join(root,f))
--
http://mail.python.org/mailman/listinfo/python-list
Re: Determining if file is valid image file
André wrote: > I should have added: I'm interesting in validating the file *content* > - not the filename :-) Some formats have identifying headers... I think jpeg is an example of this. Open it with a hex editor or just read the first few bytes and see for yourself. Brad -- http://mail.python.org/mailman/listinfo/python-list
passing vars to py scipts in cron jobs
What's the proper way to call a py script and pass in variables while doing cron jobs? I can run the scripts fine from idle, python, etc using raw_input() to prompt users. The scripts have classes with methods that need arguments. Here's an example... I want to run c1.d1(v,v,v) then c2.d2(v,v,v) class c1: # User defined vars def d1(var1, var2, var3): pass class c2: # User defined vars def d2(var1, var2, var3): pass Thanks, Brad -- http://mail.python.org/mailman/listinfo/python-list
This bit of code hangs Python Indefinitely
url_queue = Queue.Queue(256) for subnet in subnets: url_queue.put(subnet) The problem is that I have 512 things to add to the queue, but my limit is half that... whoops. Shouldn't the interpreter tell me that I'm an idiot for trying to do this instead of just hanging? A message such as this would be more appropriate: "Hey fool, you told me to only accept 256 things and you're trying to give me 512... what's up with that?" -- http://mail.python.org/mailman/listinfo/python-list
Re: This bit of code hangs Python Indefinitely
Chris Mellon wrote: > ... the producer is designed to block if > the queue is full. You can use the put_nowait method to have it raise > an exception instead of blocking. I assumed that the behavior would have been the other way around. I should not have made that assumption. -- http://mail.python.org/mailman/listinfo/python-list
Re: This bit of code hangs Python Indefinitely
Marc 'BlackJack' Rintsch wrote: > Why did you put an upper bound to the queue? For clarity. Explicit is better than implicit, right? In our design, the queue should only have x number of things, so why not show that? Other than that, the limit is arbitrary and is not needed. -- http://mail.python.org/mailman/listinfo/python-list
Re: tests
[EMAIL PROTECTED] wrote: > You should be able to read chunks of each file in binary mode and do a > compare to check for equality. Some kind of loop should do the trick. Why not a simple md5 or sha with the hash library? -- http://mail.python.org/mailman/listinfo/python-list
Re: The Future of Python Threading
Justin T. wrote: > Hello, > > While I don't pretend to be an authority on the subject, a few days of > research has lead me to believe that a discussion needs to be started > (or continued) on the state and direction of multi-threading python. This is all anecdotal... threads in Python work great for me. I like Ruby's green threads too, but I find py threads to be more robust. We've written a tcp scanner (threaded connects) and can process twenty ports on two /16s (roughly 171K hosts) in about twenty minutes. I'm happy with that. However, that's all I've ever really used threads for, so I'm probably less of an expert than you are :) I guess it comes down to what you're doing with them. Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: The Future of Python Threading
brad wrote: > This is all anecdotal... threads in Python work great for me. I like > Ruby's green threads too, I forgot to mention that Ruby is moving to a GIL over green threads in v2.0 -- http://mail.python.org/mailman/listinfo/python-list
Assignments and Variable Substitution
I'd like to do something like this: var = '123' %s = [], %var So that, in the end, var is '123' and an empty list is named '123' as well. The list assignments are created during a loop. Thanks, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Assignments and Variable Substitution
Steve Holden wrote: > Evan Klitzke wrote: >> On 8/13/07, brad <[EMAIL PROTECTED]> wrote: >>> I'd like to do something like this: >>> >>> var = '123' >>> %s = [], %var >>> >>> So that, in the end, var is '123' and an empty list is named '123' as >>> well. The list assignments are created during a loop. >> >> You can't assign a variable whose name is 123, but you can do this >> sort of thing with setattr. >> > And why would you want a variable whose name is '123'? Just an example. -- http://mail.python.org/mailman/listinfo/python-list
Re: Script to copy database
Laurent Pointal wrote: > As you wrote about c: and f:, I imagine you are working under Windows. > IMHO you dont need Python for that. Unless you need error handling, reporting, etc. Bat scripts only go so far. -- http://mail.python.org/mailman/listinfo/python-list
post xml payload with urllib
Has anyone sent an xml payload via post using urllib? I'd like to do
something like this:
logon_request = """
"the_password"
"the_user"
"""
logon = urllib.urlopen("https://127.0.0.1/api/version/xml";, logon_request)
print logon.read()
logon.close()
127.0.0.1 expects xml via a https connection post.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft Vista and os.exec
franko353 wrote: > I have wxPython programs that work fine in Win2000/XP using os.exec(). > > They do not work in MS Vista. Has anyone else had any luck with > exec()? > > I keep getting an 'invalid option' error. > > It turn out it was really a security issue and I had to move to a > "win32process.CreateProcess" solution to fix this under Vista. > > There is a good example of using CreateProcess in the "Python > programming on Win32" book. > I've also had issues with Vista... mine have to do with the execution of scripts. I don't have a test vista box in front of me right now, all of my vmware vistas have deactivated me into 'reduced functionality mode'. Basically, on XP, when I execute a script it runs in the directory that it executed in, but in Vista, it executes elsewhere... I don't remember where exactly right off the top of my head. Other than that issue it seems to work fine even with wxPython. -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular expression use
Nick Maclaren wrote: > For reasons that I won't explain, as they are too complicated > and not terribly relevant, I am interested in discovering what > people actually use regular expressions for. Finding credit card numbers in files...among other things: http://filebox.vt.edu/users/rtilley/public/find_ccns/ -- http://mail.python.org/mailman/listinfo/python-list
Script to extract text from PDF files
I have a very crude Python script that extracts text from some (and I emphasize some) PDF documents. On many PDF docs, I cannot extract text, but this is because I'm doing something wrong. The PDF spec is large and complex and there are various ways in which to store and encode text. I wanted to post here and ask if anyone is interested in helping make the script better which means it should accurately extract text from most any pdf file... not just some. I know the topic of reading/extracting the text from a PDF document natively in Python comes up every now and then on comp.lang.python... I've posted about it in the past myself. After searching for other solutions, I've resorted to attempting this on my own in my spare time. Using apps external to Python (pdftotext, etc.) is not really an option for me. If someone knows of a free native Python app that does this now, let me know and I'll use that instead! So, if other more experienced programmer are interested in helping make the script better, please let me know. I can host a website and the latest revision and do all of the grunt work. Thanks, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Script to extract text from PDF files
David Boddie wrote: > There's a little information on that online: > http://www.glyphandcog.com/textext.html Thanks, I'll read that. > Just because inserting and encoding is well documented doesn't mean that the > reverse processes are easy. :-/ Boy, that's an understatement... most of the PDF tools (in fact almost all) I come across write PDF docs... they output things to PDF. It's like anyone can generate PDF files... it's dead simple, but extracting text out of them in an accurate, reliable manner is much more difficult. > Maybe you should look at the source code for pdftotext, if that's an option. I'm not sure it's opensource/free software with source available, but I'll look into that. > Can I suggest that you approach one or more authors of the existing Python > PDF solutions and work with them on this? There are at least four PDF parsers > written in Python out there. I appreciate that suggestion, but again, none of the current solutions I've seen and tried, extract text from pdf documents. I'd love to be proven wrong on this point. So if one of those four current PDF solutions you mention do that, please let me know. Thanks, Brad -- http://mail.python.org/mailman/listinfo/python-list
slice last 4 items from a list
Is this the correct way to slice the last 4 items from a list? x = [1,2,3,4,5,6,7,8,9] print x[-4:] It works, but is it Pythonic? -- http://mail.python.org/mailman/listinfo/python-list
Dictionary invalid token error
This works:
>>> area_group = {001:06, 002:04, 003:04, 006:9}
This does not (one the end, 09 is used instead of 9)
>>> area_group = {001:06, 002:04, 003:04, 006:09}
File "", line 1
area_group = {001:06, 002:04, 003:04, 006:09}
SyntaxError: invalid token
Why does 09 cause an invalid token while 9 does not?
###
Python 2.4.4 (#2, Apr 5 2007, 18:43:10)
[GCC 4.1.2 20061115 (prerelease) (Debian AMD64 4.1.1-21)] on linux2
--
http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary invalid token error
Tim Chase wrote: > Numbers with leading zeros are parsed as octal. 8 and 9 are invalid > digits in octal. Thus, it falls over. 00 through 07 will work fine, > but 08 and 09 will go kaput. > > http://docs.python.org/ref/integers.html > > -tkc Thanks... that makes sense. I'll store them as strings. -- http://mail.python.org/mailman/listinfo/python-list
List Question
How is this expressed in Python? If x is in y more than three times: print x y is a Python list. -- http://mail.python.org/mailman/listinfo/python-list
unit testing
Does anyone else feel that unittesting is too much work? Not in general,
just the official unittest module for small to medium sized projects?
It seems easier to write some quick methods that are used when needed
rather than building a program with integrated unittesting. I see the
value of it (the official unittest that is)... especially when there's a
lot of source code. But this...
if len(x) != y:
sys.exit('...')
is a hell of a lot easier and quicker that subclassing unittest.TestCase
on small projects :)
Do others do their own "informal" unit testing?
Just curious,
Brad
--
http://mail.python.org/mailman/listinfo/python-list
Re: Program with wx in Linux and Windows
Grant Edwards wrote: > I've been using wxPython for cross platofrm stuff on Linux and > Windows for 5+ years now for at least a dozen programs. I never > had any problems like the one you describe (though "appears > disordered" isn't much of a problem description). I write/test > on Linux, and the programs pretty much "just work" on Windows. That sums up my experience with wxPython as well. I've never had any problems. I develop on Linux and run on Linux, Mac and Windows. Brad -- http://mail.python.org/mailman/listinfo/python-list
I'm starting to think like a Pythonista
I was looking at a way to implement Ruby's upto method in python. I came up with the code below... three years ago, I would never have thought of list comprehension, today it seems second nature. This may be totally un-Pythonic, but I thought it was kind of clever. Man, for some reason, I feel like being rude and lofty acting :) low_odds = [1,3,5,7,9] # make a list containing 10 - 98 evens only big_evens = big_evens = [x for x in list(xrange(99)) if x % 2 == 0 and x >8] low_evens = [2,4,6,8] # make a list containing 11 - 99 odds only big_odds = [x for x in list(xrange(100)) if x % 2 != 0 and x >9] y = 8 if y in low_evens: ok_numbers = low_odds + big_evens + [x for x in low_evens if x <= y] -- http://mail.python.org/mailman/listinfo/python-list
Re: I'm starting to think like a Pythonista
Bjoern Schliessmann wrote: > brad wrote: >> low_odds = [1,3,5,7,9] >> # make a list containing 10 - 98 evens only >> big_evens = big_evens = [x for x in list(xrange(99)) if x % 2 == >> 0 and x >8] > > Why use xrange if you convert it to a full list in place? No > advantage there. What is the dis-advantage of using xrange over range in this circumstance? -- http://mail.python.org/mailman/listinfo/python-list
Re: I'm starting to think like a Pythonista
Erik Jones wrote: > big_evens = range(10, 100, 2) > big_odds = range(11, 100, 2) Neat, but not as clever or as hard to read as mine... I'll bet it faster though... maybe not. The upto part is here: ok_numbers = low_odds + big_evens + [x for x in low_evens if x <= y] -- http://mail.python.org/mailman/listinfo/python-list
Re: if then elif
Shawn Minisall wrote:
> I just learned about if, then elif statements and wrote this program.
> The problem is, it's displaying all of the possibilities even after you
> enter a 0, or if the fat grams are more then the total number of
> calories , that is supposed to stop the program instead of continuing on
> with the print statements that don't apply. Any idea's? thanks
Two suggestions:
1. Use raw_input instead of input or errors will occur should users
enter non-numeric characters.
>#Prompt for calories
>cal = input("Please enter the number of calories in your food: ")
>
>#Prompt for fat
>fat = input("Please enter the number of fat grams in your food: ")
2. Convert cal and fat to ints or floats for your calculations... maybe
something like this:
try:
int(cal):
except ValueError,e
sys.exit(str(e) + "Enter a number!!!")
This will catch things that cannot be converted to an int (bad user input)
Besides that, I'm pretty sure your calculations are wrong.
--
http://mail.python.org/mailman/listinfo/python-list
Finding Peoples' Names in Files
Crazy question, but has anyone attempted this or seen Python code that does? For example, if a text file contained 'Guido' and or 'Robert' and or 'Susan', then we should return True, otherwise return False. -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding Peoples' Names in Files
[EMAIL PROTECTED] wrote: > On Oct 11, 5:22 pm, brad <[EMAIL PROTECTED]> wrote: >> Crazy question, but has anyone attempted this or seen Python code that >> does? For example, if a text file contained 'Guido' and or 'Robert' and >> or 'Susan', then we should return True, otherwise return False. > > Can't you just use the string function .findall() ? > I mean *any* possible person's name... I don't *know* the names beforehand :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding Peoples' Names in Files
[EMAIL PROTECTED] wrote: > However...how can you know it is a name... OK, I admitted in my first post that it was a crazy question, but if one could find an answer, one would be onto something. Maybe it's not a 100% answerable question, but I would guess that it is an 80% answerable question... I just don't know how... yet :) Besides admitting that it's a crazy question, I should stop and explain how it would be useful to me at least. Is a credit card number itself valuable? I would think not. One can easily re and luhn check for credit card numbers located in files with a great degree of accuracy, but a number without a name is not very useful to me. So, if one could associate names to luhn checked numbers automatically, then one would be onto something. Or at least say, "hey, this file has luhn validated CCs *AND* it seems to have people's names in it as well." Now then, I'd have less to review or perhaps as much as I have now, but I could push the files with numbers and names to the top of the list so that they would be reviewed first. Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding Peoples' Names in Files
Chris Mellon wrote: > In case you're doing this for PCI validation, be aware that just the > CC number is considered sensitive and you'd get some false negatives > if you filter on anything except that. > > Random strings that match CC checksums are really quite rare and false > positives from that alone are unlikely to be a problem. Unless I > deployed this and there was a significant false positive rate I > wouldn't risk the false negatives, personally. Yes, it is for PCI. Our rate of false positives is low, very low. I wasn't aware that a number alone was a PCI violation. Thank you! On another note, we're a university (Virginia Tech) and we're subject to FERPA, HIPPA, GLBA, etc... in addition to PCI. So we do these checks for U.S. Social Security Numbers too in an effort to prevent or lessen the chance of ID theft. Unfortunately, there is no luhn check for SSNs. We follow the Social Security Administration verification guideline religiously... here's an web front-end to my logic: http://black.cirt.vt.edu/public/valid_ssn/index.html but still have many false positives on SSNs, so being able to id *names and numbers* in files would still be a be benefit to us. Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory Problems in Windows 2003 Server
amdescombes wrote: > Hi, > > I am using Python 2.5.1 > I have an application that reads a file and generates a key in a > dictionary for each line it reads. I have managed to read a 1GB file and > generate more than 8 million keys on an Windows XP machine with only 1GB > of memory and all works as expected. When I use the same program on a > Windows 2003 Server with 2GB of RAM I start getting MemoryError exceptions! > I have tried setting the IMAGE_FILE_LARGE_ADDRESS_AWARE on both > Python.exe and Python25.dll and setting the /3GB flag on the boot.ini > file to no avail. I still get the MemoryError exceptions. > > Has anybody encountered this problem before? > > Thanks in advance for any ideas/suggestions. > > Best Regards, > > André M. Descombes I forgot to mention that the OS itself or other processes may be using a lot of memory. So, just because you have 2GB, that does not mean you can access all of that at once. I would guess that 25% of memory is in constant use by the OS. So, do your IO/reads in smaller chunks similar to the example I gave earlier. Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory Problems in Windows 2003 Server
amdescombes wrote: > Hi, > > I am using Python 2.5.1 > I have an application that reads a file and generates a key in a > dictionary for each line it reads. I have managed to read a 1GB file and > generate more than 8 million keys on an Windows XP machine with only 1GB > of memory and all works as expected. When I use the same program on a > Windows 2003 Server with 2GB of RAM I start getting MemoryError exceptions! > I have tried setting the IMAGE_FILE_LARGE_ADDRESS_AWARE on both > Python.exe and Python25.dll and setting the /3GB flag on the boot.ini > file to no avail. I still get the MemoryError exceptions. > > Has anybody encountered this problem before? > > Thanks in advance for any ideas/suggestions. > > Best Regards, > > André M. Descombes How are you reading the large files? IMO, large files are better read in chunks: target_file = open(f, 'rb') while 1: data = target_file.read(8192000) if data: DO SOMETHING else: break The above reads 8MB at a time until the file has been completely read. Change the 8MB to whatever you like. -- http://mail.python.org/mailman/listinfo/python-list
Re: test if email
Florian Lindner wrote: > Hello, > is there a function in the Python stdlib to test if a string is a valid > email address? Nope, most any string with an @ in it could be a valid email addy. Send a message to the addy, if it doesn't bounce, then it's valid. -- http://mail.python.org/mailman/listinfo/python-list
Re: test if email
[EMAIL PROTECTED] wrote: > On Oct 12, 2:55 pm, Florian Lindner <[EMAIL PROTECTED]> wrote: >> Hello, >> is there a function in the Python stdlib to test if a string is a valid >> email address? here's a Perl re example... I don't know whether to laugh or cry... don't try to replicate this in Python or you'll hurt yourself. :) "... the only sure way to see if a supplied email address is genuine is to send an email to it and see if the user recieves it." http://ex-parrot.com/~pdw/Mail-RFC822-Address.html -- http://mail.python.org/mailman/listinfo/python-list
Re: test if email
Grant Edwards wrote: > If you send an e-mail to an address and you get a response, > then it's valid. No response could be valid too. The user may not respond. For automated tasks, I go with the no bounce method. When things start bouncing, do domething, but so long as they don't bounce do something else. -- http://mail.python.org/mailman/listinfo/python-list
Re: python2.5 and mysqldb
writeson wrote: ... stuck trying to get mysqldb installed and running on this > machine. I've tried with easy_install and by building from the tar > file and both return a long list of errors from a gcc compile. I'm not > sure what to do next to resolve this issue, so if anyone could give me > some guidance it would be greatly appreciated. I would stay at Python 2.3... Centos (like redhat) relies heavily on Python. Sure, you could hack it a bit and install both versions (which you obviously have), but IMO, it's not worth it. What feature of 2.5 is required that 2.3 can't do? I'd guess that the mysqldb compile is somehow being confused by the default 2.3 and the version you've installed or is conflicting with other versions of itself? Again, unless there is a compelling reason to upgrade, don't or get a more flexible OS that easily allows for this sort of thing (like Debian) Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: A Python 3000 Question
Rob Wolfe wrote: > I wonder why people always complain about `len` function but never > about `iter` or `pprint.pprint`? :) Not complaining. len is simple and understandable and IMO fits nicely with split(), strip(), etc... that's why I used it as an example, but list(), etc. could be used as examples as well: a_string.list() instead of list(a_string) > And to answer the question. In OO programming generic functions > are no less important than classes and objects. Do they not take away from the OOness of the overall language and introduce inconsistencies? -- http://mail.python.org/mailman/listinfo/python-list
A Python 3000 Question
Will len(a_string) become a_string.len()? I was just reading http://docs.python.org/dev/3.0/whatsnew/3.0.html One of the criticisms of Python compared to other OO languages is that it isn't OO enough or as OO as others or that it is inconsistent. And little things such as this seem to support those arguments. Not that it matters really... just seems that classes with methods used in a more consistent manner would be more appropriate in an OO langauage. Is there a reason that len cannot be a method? a_string.lower() makes sense, as does a_string.split(), a_string.strip()... why not a_string.len()? -- http://mail.python.org/mailman/listinfo/python-list
Re: setting variables in outer functions
Tommy Nordgren wrote: >> def outer(avar=False): >> print avar >> if avar == True: >> return >> >> def inner(avar=True): >> print avar >> return avar >> >> outer(inner()) >> >> outer() > This is not a general solution to this problem. Run my example code, it works (if I'm understanding your question correctly). It sets outer to True... inner returns True to outer and thus the var is set... am I missing something? -- http://mail.python.org/mailman/listinfo/python-list
Re: setting variables in outer functions
Tommy Nordgren wrote: > Given the following: > def outer(arg) > avar = '' > def inner1(arg2) > # How can I set 'avar' here ? Try this... works for me... maybe not for you? def outer(avar=False): print avar if avar == True: return def inner(avar=True): print avar return avar outer(inner()) outer() -- http://mail.python.org/mailman/listinfo/python-list
Re: A Python 3000 Question
Eduardo O. Padoan wrote: > This is a FAQ: > http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm Thanks to all for the feedback. I'm no language designer. I just see and hear these criticisms and I wanted to think through it a bit by posting here. I now better understand generic functions and why they are used in some cases. -- http://mail.python.org/mailman/listinfo/python-list
Understanding tempfile.TemporaryFile
Wondering if someone would help me to better understand tempfile. I
attempt to create a tempfile, write to it, read it, but it is not
behaving as I expect. Any tips?
>>> x = tempfile.TemporaryFile()
>>> print x
', mode 'w+b' at 0xab364968>
>>> print x.read()
>>> print len(x.read())
0
>>> x.write("1234")
>>> print len(x.read())
0
>>> x.flush()
>>> print len(x.read())
0
--
http://mail.python.org/mailman/listinfo/python-list
Patches to Python 2.5.1
I was just looking through the 2.5.1 source code. I noticed a few mis-spellings in the comments. No big deal really. Can patches be submitted that correct the spelling errors or should they just be pointed out to some mailing list? Thanks, Brad -- http://mail.python.org/mailman/listinfo/python-list
Python 3000 and import __hello__
Just playing around with Python3000 a2 release on Windows XP 32-bit x86. import __hello__ doesn't print 'hello world...' as it does on 2.5 The import doesn't fail or generate errors... just no output. Perhaps this is by design? Brad -- http://mail.python.org/mailman/listinfo/python-list
Email Directly from python
I'd like to send email directly from within python without having to rely on an external smtp server. You know, something like the good, old Unix... echo My_message | mail -s Subject [EMAIL PROTECTED] Can Python do something similar in a portable fashion without a smtp server installed on the machine? Thanks, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Directly from python
Martin P. Hellwig wrote: > The tricky part is how to resolve the mail server for a mail address. > Usually you have to query the mx record of that domain. I solved that by > looking if I can find the nslookup binary. The from and to are static constants... they don't change. Mail just seems so tricky these days what with all the blacklists, greylists, whitelists, etc. It's almost as if email is broken. Location of the sending pc matters too. Just wondering if there is a super simple one liner in Python (that's portable) that can do this. -- http://mail.python.org/mailman/listinfo/python-list
Understanding While Loop Execution
Hi folks, I'm still fairly new to programming in python and programming in general. A friend of mine is in a CompSci 101 course and was working on a slider game when he encountered a problem. We eventually figured out what the problem was and built a test case to help solve it, but I can't for the life of me figure out the why behind it. I tried googling it and searching the list but didn't find anything that really explained it. I'm sure it's probably just both of us misunderstanding what the "while" statement does. So I hoped to ask for some clarification here. So here is what we worked out was going on with his code. from random import shuffle mylist=[2,1,3] baselist=[1,2,3] newlist=[] count=0 while mylist!=baselist: count+=1 shuffle(mylist) newlist.append(mylist) print count, mylist, newlist Output: >>> 1 [3, 1, 2] [[3, 1, 2]] 2 [1, 2, 3] [[1, 2, 3], [1, 2, 3]] >>> What he wanted was a list of lists to use later as a replay. What we expected newlist.append(mylist) to do was to save a copy of mylist into the collection for each iteration of the while statement. However, what struck us as odd is that for each time the while loop executes it changes all the lists in the list. What I found even exasperating was if I created yet another list. from random import shuffle mylist=[2,1,3] baselist=[1,2,3] newlist=[] saved_shufs=[] count=0 while mylist!=baselist: count+=1 shuffle(mylist) newlist.append(mylist) saved_shufs.append(newlist[0]) print count, mylist, newlist[0], saved_shufs Output: >>> 1 [1, 3, 2] [1, 3, 2] [[1, 3, 2]] 2 [3, 2, 1] [3, 2, 1] [[3, 2, 1], [3, 2, 1]] 3 [1, 2, 3] [1, 2, 3] [[1, 2, 3], [1, 2, 3], [1, 2, 3]] >>> newlist[0] printed out correctly but when appending it into saved_shufs it still overwrote everything. Eventually, after plinking about I remembered that tuples were immutable and wound up creating a variable like tuple_of_mylist=tuple(mylist) then appending that into newlist. That kept the list of tuples fine. I'm still wondering though what I'm not grasping about "while" that made it do that to the lists? Or is it not even while, is it something else I'm not getting? Thanks in advance, B -- http://mail.python.org/mailman/listinfo/python-list
Pass data from Python to C++
I have some c++ binaries that do rather intense number computations. They do it well and rather quickly compared to other languages (not just Python). An example: [EMAIL PROTECTED]:~/$ date && ./compute.cpp.o < 1_million.txt > /dev/null && date Thu May 15 13:08:28 EDT 2008 Thu May 15 13:08:31 EDT 2008 [EMAIL PROTECTED]:~/$ date && python compute.py < 1_million.txt > /dev/null && date Thu May 15 13:08:38 EDT 2008 Thu May 15 13:14:50 EDT 2008 In this case, c++ does one million things in 3 seconds that Python takes more than 6 minutes to do. The one million is a minimum. At times the computations are in the billions. This is why c++ was chosen. However, other components can be written in a more user friendly, more easily maintained language. We've chosen Python for this. The main question now is how to pass the computationally heavy info to c++ from within Pyhton. os.system is not ideal. Just wondering how other folks do this? I have source to some of the c++ code, but some of it is in binary from only. It can take stdin or arguments. Thanks for any tips, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python for programming algorithms
Vicent Giner wrote: The usual answer is that development time is more important than running time. This depends. Run time is not important until you are asked to scale to millions or billions of users or computations or large data sets. I've seen this first hand. Getting results back the same day or sooner may be important. In cases such as this, I use C or C++... nothing else will do. Nothing else is as fast. Although I always keep a py version around for testing and for smaller tasks. Don't get me wrong, I love Python, but there are times when nothing, but pure, hard speed will do. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem boost::python::import
Frédéric Degraeve wrote: Hello, I tried this code with vs7-8 and boost1.34.1-1.35.0 and my python is a 2.4.. Try the boost users list: To subscribe or unsubscribe via the World Wide Web, visit http://lists.boost.org/mailman/listinfo.cgi/boost-users -- http://mail.python.org/mailman/listinfo/python-list
Re: Shell-independent *nix setup script
[EMAIL PROTECTED] wrote: Hi, Is it worthwhile maintaining a production application setup script in Python as opposed to shell-script? I do not think so. Perhaps 'in conjunction with', but not 'opposed to'... sh is the lowest common denominator of shells. Script for sh and your script will run on most any Unix. Python is gaining acceptance, but is still not present everywhere by default... Solaris for example. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
cm_gui wrote: Python is slow. It ain't C++, but it ain't a punch card either... somewhere in between. I find it suitable for lots of stuff. I use C++ when performance really matters tho... right tool for the job. Learn a good interpreted language (Pyhton) and a good compiled language (C or C++) and you'll be just fine. Until then, quit bitching. -- http://mail.python.org/mailman/listinfo/python-list
Re: MVC
George Maggessy wrote: Hi Gurus, I'm a Java developer and I'm trying to shift my mindset to start programming python. So, my first exercise is to build a website. However I'm always falling back into MVC pattern. I know it's a standard, but the implementation language affects the use of design patter. So, here goes my question. Is that OK if I follow this? ... Yes. Python does not impose design patterens onto developers. Pick your poison. It is somewhat OOP, but allows for other development paradigms as well... rather like C++ IMO although a bit more OOP focused. Best of luck, Brad -- http://mail.python.org/mailman/listinfo/python-list
Looking for lots of words in lots of files
Just wondering if anyone has ever solved this efficiently... not looking for specific solutions tho... just ideas. I have one thousand words and one thousand files. I need to read the files to see if some of the words are in the files. I can stop reading a file once I find 10 of the words in it. It's easy for me to do this with a few dozen words, but a thousand words is too large for an RE and too inefficient to loop, etc. Any suggestions? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular expression help
[EMAIL PROTECTED] wrote:
Hello,
I am new to Python, with a background in scientific computing. I'm
trying to write a script that will take a file with lines like
c afrac=.7 mmom=0 sev=-9.56646 erep=0 etot=-11.020107 emad=-3.597647
3pv=0
extract the values of afrac and etot...
Why not just split them out instead of using REs?
fp = open("test.txt")
lines = fp.readlines()
fp.close()
for line in lines:
split = line.split()
for pair in split:
pair_split = pair.split("=")
if len(pair_split) == 2:
try:
print pair_split[0], "is", pair_split[1]
except:
pass
Results:
IDLE 1.2.2 No Subprocess
>>>
afrac is .7
mmom is 0
sev is -9.56646
erep is 0
etot is -11.020107
emad is -3.597647
3pv is 0
>>>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping C with Python
RPM1 wrote: ... Basically you just compile your C code as a regular C code dll. ctypes then allows you to access the functions in the dll very easily. Does that work with C++ code too or just C? -- http://mail.python.org/mailman/listinfo/python-list
Re: What Python looks like
Gary Herron wrote:
My impression was (and still is):
A page of Python code looks *clean*, with not a lot of
punctuation/special symbols and (in particular) no useless lines
containing {/} or begin/end or do/done (or whatever).
what about all those 'self' thingys? :)
--
http://mail.python.org/mailman/listinfo/python-list
regex search loops instead of findall
Hi guys... I'm trying to make my Python regex code behave like my C++
regex code. In order to search large strings for *all* occurrences of
the thing I'm searching for, I loop like this in C++:
void number_search(const std::string& portion, const boost::regex& Numbers)
{
boost::smatch matches;
std::string::const_iterator Start = portion.begin();
std::string::const_iterator End = portion.end();
while (boost::regex_search(Start, End, matches, Numbers))
{
std::cout << matches.str() << std::endl;
Start = matches[0].second;
}
}
I cannot figure out how to do the same in Python. I've read several Py
regex docs, but none of them go into examples of this, although search
seems that it should be able to loop on position according to the docs.
I've resorted to using find_all in python, but that has limitations
(especially when searching for groups) and seems to be a lot less
efficient than search. Any suggestions or example code I can look at?
I've read these:
http://www.amk.ca/python/howto/regex
http://docs.python.org/lib/module-re.html
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Suggestion for converting PDF files to HTML/txt files
srinivasan srinivas wrote: Could someone suggest me ways to convert PDF files to HTML files?? Does Python have any modules to do that job?? Thanks, Srini Unless there is some recent development, the answer is no, it's not possible. Getting text out of PDF is difficult (to say the least) and at times impossible... i.e. a PDF can be an image that contains some text, etc. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.system question
Kevin Walzer wrote:
>>> import os
>>> foo = os.system('whoami')
kevin
>>> print foo
0
>>>
The standard output of the system command 'whoami' is my login name. Yet
the value of the 'foo' object is '0,' not 'kevin.' How can I get the
value of 'kevin' associated with foo?
Hi Kevin, check out popen. It should let you do what you want.
import os
name=os.popen('whoami').read()
--
http://mail.python.org/mailman/listinfo/python-list
Editing a file by substitution
Hi, what I'd like to do is edit an input file for a calculation with
Python. Let's say that I have an input file like the following
-->>
BLAH BLAH BLAH
Other inputs, Volume 940 m^3, maybe some more stuff
STUFF STUFF
-->>
So let's say I want to edit this file and change Volume from 940 to 950.
This is how I would guess I would do something like it:
-
import re
expr=r'.*Volume\s+(?P\d+[.]?[\d+]?)'
exprComp=re.compile(expr)
infile=open('myfile','r')
outfile=open('outfile','w')
for line in infile:
match=exprComp.search(line)
if match:
newline=
print >> outfile, newline
else:
print >> outfile, line
infile.close()
outfile.close()
--
So what I would like to do in the section labeled is to use
something like the re.sub() function and replace the contents of the
"VolValue" group with another number. However I am not sure how exactly
to do this. I feel like I could use the information that's on this
website:http://www.regular-expressions.info/python.html to do it but it
seems that I can only USE captured groups, not REPLACE them. This makes
it seem to me that I would need my groups to be everything that I WASN'T
going to replace. Then I could do something like this:
re.sub(regex,\g950\g)
or something along those lines. Although that is really so much uglier
than if i could simply replace the captured group.
Please help pythonistas :)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Editing a file by substitution
alex23 wrote:
On Aug 12, 12:03 pm, Brad <[EMAIL PROTECTED]> wrote:
So let's say I want to edit this file and change Volume from 940 to 950.
Personally, I'd recommend avoiding re and sticking with the standard
string functions.
Something like this should be pretty effective:
open('outfile','w').writelines(l.replace('Volume 940','Volume 950') for l in
open('myfile','r'))
Ahh yes, perhaps string function are simpler to use in this case.
Thanks Alex!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Suggestion for converting PDF files to HTML/txt files
alex23 wrote: PDFMiner is a set of CLI tools written in Python, one of which converts PDF to text, HTML and more: http://www.unixuser.org/~euske/python/pdfminer/index.html Very neat program. Would be cool if it could easily integrate into other py apps instead of being a standalone CLI tool. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestion for converting PDF files to HTML/txt files
alex23 wrote: On Aug 12, 11:13 pm, brad <[EMAIL PROTECTED]> wrote: Very neat program. Would be cool if it could easily integrate into other py apps instead of being a standalone CLI tool. Perhaps, but I think you could get a long way using os.system(). Yes, that is possible, but there's a lot of overhead when doing that... unfortunately. Also, if using os.system() is the answer, then one could just use the xpdf pdftotext program. A native Python solution that could be called from other PY apps naturally, would be awesome. -- http://mail.python.org/mailman/listinfo/python-list
Re: Formatting input text file
[EMAIL PROTECTED] wrote: Hi, it's me again with tons of questions. I hava an input file structured like this: X XYData-1 1. 3.08333 > number1 number2 number3 number4 number5 number6 split is your friend. -- http://mail.python.org/mailman/listinfo/python-list
some path issues on windows
When reading a file into a list that contains windows file paths like this:
c:\documents and settings\brad\desktop\added_software\asus\a.txt
I get a list that contains paths that look like this:
c:\\documents and settings\\brad\\desktop\\added_software\\asus\\a.txt
So, my list contains those funky file paths. And, when I do this:
for root, dirs, files in os.walk('C:\\'):
for f in files:
print os.path.join(root,f)
I get the more normal path again:
c:\documents and settings\brad\desktop\added_software\asus\a.txt
This makes path comparison difficult as I have different strings (the
extra \'s). I've tried os.path.normpath(line_reading_in_from_file) but I
still get the funky \\ paths. How can I read the paths with an r'path'
like meaning?
Thanks,
Brad
--
http://mail.python.org/mailman/listinfo/python-list
Re: some path issues on windows
Steven D'Aprano wrote: > On Fri, 28 Mar 2008 22:31:07 -0400, Brad wrote: > >> When reading a file into a list that contains windows file paths like >> this: >> >> c:\documents and settings\brad\desktop\added_software\asus\a.txt >> >> I get a list that contains paths that look like this: >> >> c:\\documents and settings\\brad\\desktop\\added_software\\asus\\a.txt > > > What makes you think that there are doubled backslashes in the string? > Look at this: Sorry, my mistake... when testing with prints, printing the list itself showed double backslashes \\ in the paths, but when printing each path individually, it's only one back... should have tested more before posting. My apologies. Brad -- http://mail.python.org/mailman/listinfo/python-list
comparing dictionaries
I want to compare two dicts that should have identical info just in a
different data structure. The first dict's contents look like this. It
is authoritative... I know for sure it has the correct key value pairs:
{'001' : '01'}
The second dict's contents are like this with a tuple instead of a
string for the key:
{('This is one', '001'): '01'}
Pseudo Code:
for key, value in first_dict.iteritems():
# How do I do the following line?
if key not in second_dict or if it is, but has has the wrong value,
then let me know
--
http://mail.python.org/mailman/listinfo/python-list
Python multimap
Recently had a need to us a multimap container in C++. I now need to write equivalent Python code. How does Python handle this? k['1'] = 'Tom' k['1'] = 'Bob' k['1'] = 'Joe' ... Same key, but different values. No overwrites either.... They all must be inserted into the container Thanks, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Python multimap
Mike Kent wrote:
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
k = {}
k['1'] = []
k['1'].append('Tom')
k['1'].append('Bob')
k['1'].append('Joe')
k['1']
['Tom', 'Bob', 'Joe']
There is only one '1' key in your example. I need multiple keys that are
all '1'. I thought Python would have something built-in to handle this
sort of thing.
I need a true multimap:
k['1'] = 'Tom'
k['1'] = 'Tommy'
without Tommy overwriting Tom and without making K's value a list of
stuff to append to. That's still just a regular map.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python multimap
castironpi wrote: I don't understand what a multimap does that a map of lists doesn't do. It counts both keys individually as separate keys. The Python workaround does not... see examples... notice the key(s) that are '4' Python output (using the k = [] idea): Key: 4 Value: [[13, 'Visa'], [16, 'Visa']] Key: 51 Value: [16, 'MC'] Key: 65 Value: [16, 'Discover'] Key: 2131 Value: [15, 'JCB'] Key: 300 Value: [14, 'Diners CB'] Key: 301 Value: [14, 'Diners CB'] Key: 302 Value: [14, 'Diners CB'] Key: 303 Value: [14, 'Diners CB'] Key: 304 Value: [14, 'Diners CB'] Key: 305 Value: [14, 'Diners CB'] Key: 35 Value: [16, 'JCB'] Key: 34 Value: [15, 'Amex'] Key: 55 Value: [16, 'MC or Diners US and CA'] Key: 36 Value: [14, 'Diners Intl'] Key: 37 Value: [15, 'Amex'] Key: 1800 Value: [15, 'JCB'] Key: 54 Value: [16, 'MC'] Key: 6011 Value: [16, 'Discover'] Key: 52 Value: [16, 'MC'] Key: 53 Value: [16, 'MC'] Key: 385 Value: [14, 'Diners CB'] 21 is the size of the dict A C++ multimap Key: 1800 Value: JCB 15 Key: 2131 Value: JCB 15 Key: 300 Value: Diners_Club 14 Key: 301 Value: Diners_Club 14 Key: 302 Value: Diners_Club 14 Key: 303 Value: Diners_Club 14 Key: 304 Value: Diners_Club 14 Key: 305 Value: Diners_Club 14 Key: 34 Value: American_Express 15 Key: 35 Value: JCB 16 Key: 36 Value: Diners_Club 14 Key: 37 Value: American_Express 15 Key: 385 Value: Diners_Club 14 Key: 4 Value: Visa 16 Key: 4 Value: Visa 13 Key: 51 Value: MasterCard 16 Key: 52 Value: MasterCard 16 Key: 53 Value: MasterCard 16 Key: 54 Value: MasterCard 16 Key: 55 Value: MasterCard 16 Key: 6011 Value: Discover 16 Key: 65 Value: Discover 16 22 is the size of the multimap -- http://mail.python.org/mailman/listinfo/python-list
Re: Python multimap
Carl Banks wrote: Out of curiosity, what does a true multimap solve that a dictionary of lists not solve? Nothing really. I went with a variation of the suggested work around... it's just that with Python I don't normally have to use work arounds and normally one obvious approach is correct: -- http://mail.python.org/mailman/listinfo/python-list
Re: Feature request: String-inferred names
On Nov 25, 10:49 pm, Chris Rebert wrote: > On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy > > wrote: > > Hello all, > > > I just posted to my blog about a feature that I'd like to see added to > > Python. Before I go through the trouble of learning how to write a PEP or > > how to extend the Python interpreter, I want to know what people in the > > community have to say about it. > > >http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor... > > > As far as I know, a feature like this does not appear in any existing PEPs. > > (If it does I would appreciate it if someone could tell me what PEP it is.) > > > Please give and comments you may have, but I request that you be > > constructive if you must criticize...thank you! > > Ugly, Perlish, and as you even admit, entirely unnecessary. > And you'd need to wait at least a year > anyway:http://www.python.org/dev/peps/pep-3003/ > > Cheers, > Chris > --http://blog.rebertia.com Like I said, lots of things in Python are "unnecessary," but that doesn't make them "useless," and it certainly doesn't mean they shouldn't exist. My proposed feature is not useless; I think it would make a lot of code easier. As for it being ugly...well, that's really a matter of opinion and experience. How ugly it looks to you will be a product of how well you think it can be used, and how well you use it yourself. When I first looked at decorators, I thought they were not only ugly but confusing. Now that I understand them, however, I hardly consider them "ugly," and see them as a shining example of Python's abilities. (By the way, decorators are another example of a feature that is "entirely unnecessary," but still very useful.) As for the wait, that's to be expected. I'm willing to wait. -- http://mail.python.org/mailman/listinfo/python-list
