Re: Development tools and practices for Pythonistas

2011-04-30 Thread Shawn Milochik
For what it's worth, the Python core developers have selected Mercurial. 
I personally use git and love it. Most open-source people seem to use 
one or the other of the two. They're pretty similar in most ways.


Look at the big two sites for open-source repositories -- github and 
bitbucket. One's git, the other Mercurial. I don't think you can go 
wrong picking either one.



--
http://mail.python.org/mailman/listinfo/python-list


Re: Development tools and practices for Pythonistas

2011-04-29 Thread Shawn Milochik
Depends on the project, but I'd start with git the time I created the 
first file in my project. If you're in the habit of committing then you 
can easily rollback missteps. If you're in the habit of making branches 
you can experiment without breaking the currently-working code.



--
http://mail.python.org/mailman/listinfo/python-list


Re: Unix-head needs to Windows-ize his Python script

2010-10-20 Thread Shawn Milochik
Write a small GUI in the easy-to-use and cross-platform wxPython module. All 
this GUI needs to do is allow them to input the arguments. The code can then 
import your stand-alone version of the script and execute its code, passing the 
arguments in.

wxPython is just Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unix-head needs to Windows-ize his Python script

2010-10-20 Thread Shawn Milochik

On Oct 20, 2010, at 2:00 PM, Grant Edwards wrote:

 On 2010-10-20, Shawn Milochik sh...@milochik.com wrote:
 ript and execute its code, passing the arguments in.
 
 wxPython is just Python.
 
 No, it's not.
 
 You can't assume that any windows machine with Python installed also
 has wxPython installed.  The only GUI kit that you can come close to
 assuming is Tkinter.
 

I didn't mean to imply that wxPython is in the standard library. Just that you 
write Python code when you create a wxPython app. I apologize for the lack of 
clarity.

I recommended wxPython instead of Tkinter because of the opinions I've heard 
from other Python developers who prefer the former (I've never used Tkinter). 
Also, wxPython automatically looks native Mac, Windows, and Linux.

Shawn


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pylint -- should I just ignore it sometimes?

2010-10-19 Thread Shawn Milochik
Just to be pedantic (or maybe even helpful), the use of the comma
after the exception is deprecated in favor of 'as.'

So:

except ValueError as ex:

not:

except ValueError, ex:

I don't know how far back in Python versions this syntax reaches, but
if yours supports it then it's probably a good idea to get into the
habit.
This way, you can catch multiple exceptions in a tuple without
confusing the interpreter:

except ValueError, IndexError as ex:

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When will Python go mainstream like Java?

2010-02-22 Thread Shawn Milochik
When will Java be popular enough to replace other languages in their own 
environments, the way Python has done to Java (Jython) and .NET (IronPython)?

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File transfer with python

2010-01-07 Thread Shawn Milochik
Have a look at Paramiko. It lets you do secure transfers easily (scp/sftp)

http://www.lag.net/paramiko/

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python books, literature etc

2010-01-06 Thread Shawn Milochik
Search Google. You'll find it all.

Search this list's archives. This kind of thing has been discussed a thousand 
times.

It also wouldn't hurt to brush up on this:
http://catb.org/~esr/faqs/smart-questions.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie help- Can multiple instances with multiple names automatically created.

2010-01-04 Thread Shawn Milochik
You could put them in a dictionary with the key being the name, instead of a 
list.

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie help- Can multiple instances with multiple names automatically created.

2010-01-04 Thread Shawn Milochik

On Jan 4, 2010, at 5:59 PM, Nav wrote:

 On Jan 4, 4:54 pm, Chris Rebert c...@rebertia.com wrote:
 On Mon, Jan 4, 2010 at 1:32 PM, Shawn Milochik sh...@milochik.com wrote:
 You could put them in a dictionary with the key being the name, instead of 
 a list.
 
 To illustrate that for the OP:
 
 name2drink = {}
 for booze in liquors:
 for juice in juices:
 name = juice + +booze # or however you're naming them
 drink = Bottle(booze, juice)
 name2drink[name] = drink
 
 #example use
 favorite = name2drink[apple wine]
 favorite.rating = 9/10
 
 typing
 favorite = such and such is what I am trying to avoid.
 
 I want to be able to use the name 'apple_wine' as the variable which
 has the object apple wine but not have to do this manually as you did
 with favorite.
 
 
 
 
 

Then don't assign a variable to favorite, and just use name2drink[apple wine].
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple distributed example for learning purposes?

2009-12-28 Thread Shawn Milochik

On Dec 27, 2009, at 1:23 PM, Lie Ryan wrote:
 
 IMHO, that's a poor example. Rather than writing a fuzzy search algorithm, 
 it's easier to write a normalizer before entering data to the index (or 
 before comparing the search string with the corpus' string).
 -- 
 

It does seem like that at first, but it turns out that you can't normalize this 
data, for many reasons.

With address data:
one address may have suite data and the other might not
the same city may have multiple zip codes
incoming addresses may be missing information
typos are common
sometimes Route 35 is the same road as Convery Boulevard
etc. etc. etc.

With names:
you have to compare with and without the middle name
compare with and without the title (Mrs., Dr., Mr., Ms.)
compare with and without the suffix (PhD., Sr., Junior, III, etc.)
typos are VERY common
what if John Henry Smith goes by Henry Smith?
what if Xu Wang goes by John Wang (happens all the time)
maiden name versus married name
etc. etc. etc.

This is a major, real-world issue that remains unsolved, and companies that do 
a decent job at it make millions of dollars a year from their clients. One of 
my old jobs made tens of millions a year (and growing FAST) in the  medical 
industry alone. 

Shawn


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple distributed example for learning purposes?

2009-12-28 Thread Shawn Milochik

On Dec 28, 2009, at 11:28 AM, Lie Ryan wrote:
 
 I agree fuzzy searches is indispensable in certain cases, but from the way 
 you're describing the issue, it appears that half of your unsolved problems 
 comes due to the poor design of the database. I agree, that the other halves 
 (e.g. typos, multiple names/addresses) are indeed unsolvable.

Your comments make some sense, but they do not work when it comes to real-world 
data. Trust me, I've seen all kinds of data from all kinds of clients, and no 
matter how well-designed and well-indexed your database is, the incoming data 
is going to be a problem.

Shawn-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple distributed example for learning purposes?

2009-12-27 Thread Shawn Milochik
The special features of the Shrek DVD showed how the rendering took so much 
processing power that everyone's workstation was used overnight as a rendering 
farm. Some kind of video rendering would make a great example. However, it 
might be a lot of overhead for you to set up, unless you can find someone with 
expertise in the area. The nice thing about this is that it would be relevant 
to the audience. Also, if you describe what goes into processing a single frame 
in enough depth that they appreciate it, they'll really get the power of 
distributed processing.

Something else incredibly time-expensive but much easier to set up would be 
matching of names and addresses. I worked at a company where this was, at its 
very core, the primary function of the business model. Considering the 
different ways of entering simple data, many comparisons must be made. This 
takes a lot of time, and even then the match rates aren't necessarily going to 
be very high.

Here are some problems with matching:

Bill versus William
'52 10th Street' | '52 tenth street'
'E. Smith street' | 'E smith street' | 'east smith street'
'Bill Smith' | 'Smith, Bill' 
'William Smith Jr' | 'William Smith Junior'
'Dr. W. Smith' | 'William Smith'
'Michael Norman Smith' | 'Michael N. Smith' | 'Michael Smith' | 'Smith, 
Michael' | 'Smith, Michael N.' | 'Smith, Michael Norman'

The list goes on and on, ad nauseum. Not to mention geocoding, married and 
maiden names, and scoring partial name matches with distance proximity matches. 
Another nice thing is that, depending on how much time you want to spend on it, 
you can have the students refine the matching rules over time, and see how 
those rules effect the match rate and the processing time. On the downside, 
your class will not have the joy of being taught the 'ideal solution' to this 
problem at the end; if you come up with that, you'll be able to go into 
business and make millions of dollars a year. ^_^

Shawn




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to iterate the input over a particular size?

2009-12-27 Thread Shawn Milochik
A couple of notes:

Your code is too packed together. That makes it hard to read. Put in some 
whitespace (and comments, where necessary), and put spaces around your equal 
signs (x = 23 instead of x=23).

That said, here's something I threw together:

#!/usr/bin/env python

def chop_list(words, size = 9):


Take a list, returning values
from the end of the list, and
the original list minus those values.

 chop_list(['test', 'with', 'four', 'words'], 2)
(['test', 'with'], ['four', 'words'])

 chop_list(['test', 'with', 'four', 'words'], 3)
(['test'], ['with', 'four', 'words'])

 chop_list(['test', 'with', 'four', 'words'], 4)
([], ['test', 'with', 'four', 'words'])




chopped = words[-size:]
old_to_return = len(words) - len(chopped)

return words[:old_to_return], chopped


if __name__ == '__main__':

import doctest
doctest.testmod()

sample_string = '''There are more than nine words here. 
I know because I wrote them.'''

word_list = sample_string.split()

while word_list:

word_list, new = chop_list(word_list)
print Pulled off:\t%s\n\tRemaining: %s % (new, word_list)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: DB Table Processor?

2009-12-27 Thread Shawn Milochik
It sounds like you're looking for SQLAlchemy.

http://www.sqlalchemy.org/

Enjoy!

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: handling https sites

2009-06-26 Thread Shawn Milochik


On Jun 26, 2009, at 12:08 PM, padfoot wrote:


Sir,
Is there any module in python to open https sites through a
proxy.I am connectyed to the net via a proxy server and i am unable to
crawl https sites.
--
http://mail.python.org/mailman/listinfo/python-list


Check out the Scrape the Web series from the 2009 PyCon:

http://advocacy.python.org/podcasts/


--
http://mail.python.org/mailman/listinfo/python-list


Re: Your Favorite Python Book

2009-05-11 Thread Shawn Milochik
It depends on what you want to do. If you still want to beef up on
general knowledge, maybe skim through The Python Cookbook or
something reference-like.

If you feel ready to start doing something with Python, look into one
of the recent titles that applies Python for a specific purpose.
Examples:

Gray Hat Python (debugging, reverse engineering)
Natural Language Processing with Python (pre-order at this time)
Any up-to-date (version 1.0 and up) Django book (if you're into Web development)
Expert Python Programming (best practices)
Beginning Python Visualization (presenting data visually)
Programming Collective Intelligence (extracting valuable information
from public data sources, and more)

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fill Javascript form

2009-05-11 Thread Shawn Milochik
How is the form written in JavaScript? Is it dynamically generated?

In any case, can you just send a POST request if you know the values required?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Your Favorite Python Book

2009-05-11 Thread Shawn Milochik
On Mon, May 11, 2009 at 5:52 PM,  pyt...@bdurham.com wrote:
 Sam,

 In no specific order (I brought them all):

 Wesley Chun's Core Python Programming
 David Mertz's Text Processing in Python (older, but excellent)
 Mark Lutz's Learning Python

 All highly recommended.

 Best of luck on your Python journey!

 Regards,
 Malcolm
 --
 http://mail.python.org/mailman/listinfo/python-list


I second the Wesley Chun recommendation wholeheartedly. Also, Text
Processing in Python is available for free online.

http://gnosis.cx/TPiP/

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginning Python Visualization by Shai Vaingast

2009-05-10 Thread Shawn Milochik
Thanks for the review and the podcast. I ordered the book on Friday. I
look forward to playing with it. Also (assuming you're Ron Stephens),
thanks for the Python 411 podcast. It's a great resource, and I
recommend it to all list members.

Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: Downloading most recently modified files

2009-05-10 Thread Shawn Milochik
On Sun, May 10, 2009 at 1:04 PM, AllenLars allenr...@gmail.com wrote:

 Thanks Shawn.  I went through the ftplib info and I was able to generate a
 list.  I am needing to figure out parsing the list.

 AllenLars


Well, start by separating out the date and the file name. You'll want
the date for sorting, and the file name for when you decide to
download it. If you want help with regular expressions, let me know.
If so, post a sample of the code you have so far for parsing, sample
input (the raw listing), and sample output showing exactly how you
want it to look. As long as you write some code (even if it's not
working the way you want), I don't mind helping you fix it up.
--
http://mail.python.org/mailman/listinfo/python-list


OT (humor): 'import antigravity' in action!

2009-05-09 Thread Shawn Milochik
I know you've probably all seen this 50 times, but just in case:
http://xkcd.com/353/

And here's the result:
http://icanhascheezburger.com/2009/05/06/funny-pictures-behavior-20/
--
http://mail.python.org/mailman/listinfo/python-list


Re: xml in python

2009-05-09 Thread Shawn Milochik
On Fri, May 8, 2009 at 3:46 AM, Rustom Mody rustompm...@gmail.com wrote:
 Can someone give me a heads up on xml parsing in python?
 The context is that I want to write a simple docbook to text converter.
 DOM is alright -- dont want to break my head with SAX just for performance
 when my documents are not likely to be large.

 My problem is that there seems to be so many nearly equivalent ways (Pyxml?
 Amara?) some of which have moved from 3rd party to builtin status that I am
 not clear what is the current method of choice.

 Thanks
 --

I've been using minidom for simple XML processing with success. The
XML module seems to be the way to go, considering how many of its
child modules are listed on http://docs.python.org/library/.

import xml.dom.minidom as minidom

Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: Downloading most recently modified files

2009-05-07 Thread Shawn Milochik
On Thu, May 7, 2009 at 2:19 PM, AllenLars allenr...@gmail.com wrote:

 I am trying to code a script that will allow me to go to ftp site and
 download files based on most recently modified file (date, time).  I am
 brand new to programming.  Any and all help is appreciated.
 --snip


I've actually written code to do this, and it's fairly easy. Just use
the FTP module to run the ls (directory listing) command and parse
the results to get the filenames and timestamps. Then you will be able
to easily do download requests for the file(s) you want.

Perhaps someone else on the list can chime in with a more elegant solution.

Here's enough to get you started:

from ftplib import FTP   #(http://docs.python.org/library/ftplib.html)

ShawnMilo
--
http://mail.python.org/mailman/listinfo/python-list


Re: Copy Paste in a Dos box (was: Pyhton script to call another program)

2009-05-06 Thread Shawn Milochik
On Wed, May 6, 2009 at 1:54 PM, Tim Chase python.l...@tim.thechases.com wrote:
 for windows this works:
 (can't cut and paste from a dos box!###%*!!!)

 Depending on how it was spawned, you can either right-click in the window
 and choose Mark/Paste (when marking, use enter to terminate the selection;
 and selections are blockwise rectangular rather than linewise or
 characterwise).  Alternatively, if you click on the system menu (the icon in
 the title-bar with resize/minimize/maximize/close/help), there should be an
 Edit submenu with the same options within.

 A pain, but at least feasible.
snip

I know I'm coming to the conversation late, but here's what I do*:

1. Use Cygwin. (http://www.cygwin.com/)
2. Use PuttyCYG (http://code.google.com/p/puttycyg/)

That way, you can basically use PuTTY to shell into your Windows box.

Note: If you are familiar with the Linux command line, you will be in
love with this solution. If you're a Windows-only type, then be
forewarned that doing this will require you to type Unix/Linux
commands (for the most part) instead of DOS commands.

*Disclaimer: I use a Mac and Linux. This is my workaround when forced
to use Windows. Your environment preferences may vary.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Copy Paste in a Dos box (was: Pyhton script to call another program)

2009-05-06 Thread Shawn Milochik
On Wed, May 6, 2009 at 2:39 PM, Grant Edwards inva...@invalid wrote:
 On 2009-05-06, Shawn Milochik sh...@milochik.com wrote:

 I know I'm coming to the conversation late, but here's what I do*:

 1. Use Cygwin. (http://www.cygwin.com/)
 2. Use PuttyCYG (http://code.google.com/p/puttycyg/)

 That way, you can basically use PuTTY to shell into your
 Windows box.

 Better yet, set up sshd in your Cygwin install, and then use
 whatever terminal you normally use on your Linux/MacOS box to
 ssh into the Cygwin box.  When run that way, windows is almost
 usable...

 --
 Grant Edwards

snip

True, but when I'm using Cygwin, that means I'm at work and don't have
a non-MS OS available. Of course I can open an ssh session to my home
machine for sanity (or kicking off a torrent download at home), but I
don't have a *nix-based OS at the day job. Lanching DSL embedded to
use the terminal seems a bit much. ^_^

Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing text

2009-05-06 Thread Shawn Milochik
On Wed, May 6, 2009 at 2:32 PM, iainemsley iainems...@googlemail.com wrote:
 Hi,
 I'm trying to write a fairly basic text parser to split up scenes and
 acts in plays to put them into XML. I've managed to get the text split
 into the blocks of scenes and acts and returned correctly but I'm
 trying to refine this and get the relevant scene number when the split
 is made but I keep getting an NoneType error trying to read the block
 inside the for loop and nothing is being returned. I'd be grateful for
 some suggestions as to how to get this working.

 for scene in text.split('Scene'):
    num = re.compile(^\s\[0-9, i{1,4}, v], re.I)
    textNum = num.match(scene)
    if textNum:
        print textNum
    else:
        print No scene number
    m = 'div type=scene'
    m += scene
    m += '\div'
    print m

 Thanks, Iain


Can you provide some sample input so we can recreate the problem?

Also, consider something like this instead of the concatenation:

m = 'div type=scene%s/div' % (scene,)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Copy Paste in a Dos box

2009-05-06 Thread Shawn Milochik
snip
 Damn! I may just go back to using Python from the command prompt
 instead of using IDLE.

 On second thought, IDLE is way too useful for indenting, dedenting,
 commenting and uncommenting blocks of code. Can't go back to using
 Notepad.

snip


You might want to check out iPython, then -- it's an interactive
Python interpreter that's meant to be used as a shell environment. It
has very useful help and auto-completion features.

If you're just talking about an IDE, you might want to try TextMate if
you're on a Mac. It's great. Notepad++ is good on Windows, but I
haven't used it in Python much, so I don't know about its indentation
features.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Battleship style game

2009-03-11 Thread Shawn Milochik
Thanks for the tips, everybody.

I've cleaned it up, and learned some useful things from your comments
and the reading they led to.

http://shawnmilo.com/ships/
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Python's regex different from Perl's , I want know what's the different?

2009-02-26 Thread Shawn Milochik
The regular expression syntax is basically exactly the same. The main
difference is that a regex can't just be written into a statement as
part of the syntax; you have to create a regular expression object and
use its methods.

So, instead of:
new_thing =~ s/pattern/replacement/
it's:
myPattern = re.compile(r'pattern')
new_thing = myPattern.sub(replacement, input_string)
or:
new_thing = re.sub(pattern, replacement, input_string)

Also, backreferences are \1 instead of $1, and you have to escape the
backslash or use a raw string for the backslash.

I've found this page to be pretty helpful:
http://www.regular-expressions.info/python.html

Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Battleship style game

2009-02-25 Thread Shawn Milochik
I started learning Java for fun, and the first project assignment in
the book is to create a game like Battleship. So, of course, I wrote
it in Python first, just for fun. I haven't had the time to look up
all the Java syntax.

So, here it is, fully functional. I thought I'd throw it out there and
see if anyone would like to offer any useful tips. I'm not claiming
it's bulletproof, but it works. I just kind of came up with all the
methods off of the top of my head, so if anyone has any suggestions
for more elegant or efficient code, please let me know.

http://shawnmilo.com/ships/

Thanks,
Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: Battleship style game

2009-02-25 Thread Shawn Milochik
On Wed, Feb 25, 2009 at 11:38 AM, Marco Mariani ma...@sferacarta.com wrote:

 Yes it's in Python alright, but it's not Pythonese yet. You could try
 avoiding the getter/setter stuff, and camelCase method naming, things like
 that, for a start.

 --
 http://mail.python.org/mailman/listinfo/python-list



What do you mean avoiding the getter/setter stuff? If I understand
correctly, you're saying to directly access the attributes, which I
specifically want to avoid because I may want to enforce some rules
(such as not changing a ship length after it's created).

The camel-case thing I get -- I use that and this_type quite a bit,
probably because of the inconsistency of the languages I use
regularly, and standards at work and conventions in my hobby
programming.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Battleship style game

2009-02-25 Thread Shawn Milochik
Thanks. I wasn't aware of the property() function, but I read up on
it. I modified the Vessels.py file, but not the board file (except
where necessary to handle the changes made to Vessels. Is this better?

http://shawnmilo.com/ships/ships2/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Battleship style game

2009-02-25 Thread Shawn Milochik
On Wed, Feb 25, 2009 at 3:15 PM, Diez B. Roggisch de...@nospam.web.de wrote:

 Not really. The point about properties is that you *can* make attribute
 access trigger getter or setter code.

 But not that you do unless there is an actual reason for that. The way you
 do it now is simply introducing clutter, without benefit. Your class would
 be half the current size - without loss of functionality.



 Diez
 --
 http://mail.python.org/mailman/listinfo/python-list


It is true that it would be fewer lines of code with the same
functionality, but it's better practice to have that framework in
place so that any changes made in the future wouldn't break any of the
code accessing my class. Obviously this is a fairly simple game that
has a fixed set of rules, but I'm trying to cultivate good habits, and
I don't think that doing it this way is anti-Pythonic.

Unless, of course, anything I said is wrong, which is always possible.
If I'm missing a bigger-picture idea, I'd like to know about it.

Thanks,
Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: re.sub and named groups

2009-02-11 Thread Shawn Milochik

 Book recommendation: _Mastering Regular Expressions_, Jeffrey Friedl
 --
 Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

I wholeheartedly second this! The third edition is out now.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Searching a file for multiple strings (PS)

2009-02-01 Thread Shawn Milochik
On Sun, Feb 1, 2009 at 1:14 AM, John Machin sjmac...@lexicon.net wrote:
 On Feb 1, 3:39 pm, Shawn Milochik sh...@milochik.com wrote:

 Not to discourage the use of Python, but it seems that fgrep with the
 -f flag already does exactly what you want. If you're on Windows, you
 can get the Windows version of fgrep here: http://unxutils.sourceforge.net/

 That URL is antique and a dead end. When you find the actual
 sourceforge project page (http://sourceforge.net/projects/unxutils/)
 and browse the forums and the CVS repository, you'll see tumbleweed
 blowing down Main Street and not much else (besides a few whinges
 about that dead end URL, and many unanswered issues).

 Alternative: http://gnuwin32.sourceforge.net/
 --
 http://mail.python.org/mailman/listinfo/python-list


Thanks very much for the update. I had been using the older versions
(on the rare occasions I've had to use Windows). I didn't know there
was a currently-maintained version.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Searching a file for multiple strings (PS)

2009-01-31 Thread Shawn Milochik
On Sat, Jan 31, 2009 at 3:00 PM, Tim Chase
python.l...@tim.thechases.com wrote:
 I'm fairly new with python and am trying to build a fairly simple
 search script.  Ultimately, I'm wanting to search a directory of files
 for multiple user inputted keywords.  I've already written a script
 that can search for a single string through multiple files, now I just
 need to adapt it to multiple strings.


Not to discourage the use of Python, but it seems that fgrep with the
-f flag already does exactly what you want. If you're on Windows, you
can get the Windows version of fgrep here:
http://unxutils.sourceforge.net/

Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: spam update

2008-11-19 Thread Shawn Milochik
On Tue, Nov 18, 2008 at 11:23 AM,  [EMAIL PROTECTED] wrote:
 With some help from the python.org postmasters over the weekend I figured
 out why some seemingly obvious spam messages seem to be making it to the
 python-list@python.org mailing list.  Messages gatewayed from Usenet don't
 pass through the spam filters.  Mailman simply distributes them.  There is
 still no resolution, but at least I understand the cause now.  For now,
 mailing list users please be patient as we try to resolve this issue.

 Thanks,

 --
 Skip Montanaro - [EMAIL PROTECTED] - http://smontanaro.dyndns.org/
 --
 http://mail.python.org/mailman/listinfo/python-list


It's like the never-ending story. This exact explanation was given to
the list over six months ago (in April) , along with the message that
there's nothing that we can do about it. Actually, it's not the
exact explanation -- it was narrowed down to posts from Google
Groups, rather than Usenet in general.

At the time there was a lot of chatter on the list about people
plonking posts from Google Groups. That's a solution, if that's
where the spam comes from, but it penalizes the legitimate users who
don't subscribe to the mailing list.

Just for what it's worth. This is an ongoing problem (although it used
to be much worse), and it's a shame that we're going in circles.

Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: Text based screens without ncurses

2008-11-14 Thread Shawn Milochik
On Thu, Nov 13, 2008 at 2:10 PM, Grant Edwards [EMAIL PROTECTED] wrote:
 On 2008-11-13, Mirat Can Bayrak [EMAIL PROTECTED] wrote:

 Hi, i'll try to write a editor in python, i want it run under
 terminal (no qt or gtk) but i dont want to use urwid or curses
 modules.

 Can i write my curses like module in python?

 Sure.  If you don't want to use the ncurses library, then you
 could use something like slang (the Python package containing
 slang is called newt).

 Or you can use terminfo/termcap like this:

 http://code.activestate.com/recipes/475116/

 i googled to find metods that curses uses to write
 characters,colors etc. on screen but it did not make sense to
 me. Can u help me?

 Probably not.

 any ideas? any suggestions?

 Well, I'd working on my spelling and typing skills and stop
 using SMS-speak on Usenet.



I second that! This list has standards. Here are a few tips:

Capitalize the word I and I'll and the like.
The word you has three letters in it, not one.
Use spell-check.
Capitalize Google and its derivatives.

In general, present yourself as someone intelligent -- not a moron.
You'll get more respect, and more help.

While I'm ranting, here's more general stuff that doesn't necessarily
apply to this thread:

Do not type anything in all caps.
Make your e-mail subject meaningful. I don't bother to read anything
with no subject, or help or some other useless title.
If your code isn't working, post it when asking the group why it doesn't work.
When your output isn't what you wanted, post sample input, actual
output, and expected output.

Proofread what you write! Not only will you be able to fix bad
writing, but upon re-reading you may notice that you are being
ambiguous, leaving out important details, or that your wording just
doesn't make sense. Think about how many threads begin with a
question, then 10 responses asking for clarification. If you ask
properly the first time, you might just get the right answer in the
first reply!

ShawnMilo
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to eliminate quotes around string field written to a file.

2008-11-14 Thread Shawn Milochik
On Sat, Nov 15, 2008 at 12:19 AM, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Fri, 14 Nov 2008 20:39:53 -0800, len wrote:

 hi

 Have this code in my program;

 filename = 'custfile'
 codeline = filename + ' = [\n'
 output.write(codeline)

 record written to file look like this

  custfile = [

 I cannot reproduce that behaviour. I suggest that the code you are
 running is not the same as the code you say you are running.
 --
 Steven


Same here. I don't get quotes around it. Also, how is output
defined? I got an error, so I used sys.stderr.write() instead.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to build the pysqlite? Where to find the sqlite3.h?

2008-11-05 Thread Shawn Milochik
This is all useful and interesting stuff, but I don't think any of it
addresses the original poster's problem, which is that he has no root
access to a Linux or Unix box, and wants to get pysqlite2 working in
his home directory. I have exactly the same problem. I have tried the
python setup.py install --home=~ method, and I get errors from GCC
that I have no permissions (and to be honest, nor the knowledge) to
overcome.

Isn't there anyway to get a Linux binary that can just be put
somewhere in the Python path so we can use sqlite? Or are those of us
without admin/root control of our boxes screwed?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parse each line by character location

2008-11-05 Thread Shawn Milochik
I work with tab-delimited files for a living. Because of the same need
you have, I created a Python script to do this. It has usage
information that is easy to follow (just run it without any
arguments).

I hope someone else finds this useful. I have, and use it every month.
It can be easily modified to create comma-delimited files, but that's
something I never use, so it does tabs.

http://milochik.com/shawn/fwconvert.zip



Usage:
fwconvert -r rulesFile fileName [-t|-f]
or
cat filename | fwconvert -r rulesFile (-t|-f)

-t (to tab) or -f (to fixed-width) required when piping input to
script. Otherwise, it will be auto-determined.


Rules file format:
fieldStart:fieldLength,fieldStart:fieldLength...
Example:
1:3,4:20,24:5
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to build the pysqlite? Where to find the sqlite3.h?

2008-11-05 Thread Shawn Milochik
On Wed, Nov 5, 2008 at 11:58 AM, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 On Nov 5, 9:22 pm, Shawn Milochik [EMAIL PROTECTED] wrote:
 This is all useful and interesting stuff, but I don't think any of it
 addresses the original poster's problem, which is that he has no root
 access to a Linux or Unix box, and wants to get pysqlite2 working in
 his home directory. I have exactly the same problem. I have tried the
 python setup.py install --home=~ method, and I get errors from GCC
 that I have no permissions (and to be honest, nor the knowledge) to
 overcome.

 Isn't there anyway to get a Linux binary that can just be put
 somewhere in the Python path so we can use sqlite? Or are those of us
 without admin/root control of our boxes screwed?

 1. Get sqlite3 from http://www.sqlite.org/sqlite-3.6.4.tar.gz
 2. build and install sqlite3 (./configure --prefix=/any/writeable/dir
  make install) -- you may want to supply the --disable-tcl flag if
 you hit permission problems
 3. get pysqlite3, edit setup.cfg libraries and include lines to point
 to the lib/ and include/ dir where you installed sqlite3 in the
 previous step
 4. python setup.py install --home=somewhere
 5. PYTHONPATH=somewhere ./python -- import pysqlite2 should work for
 you
 --


Thanks, but either I'm missing something or you're missing something.
I can't do any of what you describe on the machine I want to use
sqlite on.

I have downloaded the binary sqlite3 file from sqlite's Web site, and
I can use it with shell scripts and via the command line with no
problem. The issue is that I don't seem to have any way available to
me to use the pysqlite2 Python module.

When I try the python setup.py --install --home=somewhere
installation, it blows up on GCC errors that I do not have the
permissions to even attempt to fix.  What I was asking above was
whether there was a way do download the pysqlite2 module as files that
I can just copy into a directory that Python thinks is part of its
path so I can use it without having to compile or build it in any way
on that machine.

Thanks,
Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to build the pysqlite? Where to find the sqlite3.h?

2008-11-05 Thread Shawn Milochik
 Thanks, but either I'm missing something or you're missing something.
 I can't do any of what you describe on the machine I want to use
 sqlite on.

 I have downloaded the binary sqlite3 file from sqlite's Web site, and

 The linux binary will not work. You need the headers and the
 libraries. Grab the src tar ball and build and install locally.

 -srp

That is not correct. The binary *does* work, as I said last time.

For the third time, it is not possible for me to build from source on that box.

And in any case, you keep talking about sqlite3, but I'm talking about
pysqlite2.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to build the pysqlite? Where to find the sqlite3.h?

2008-11-05 Thread Shawn Milochik
On Wed, Nov 5, 2008 at 1:55 PM, Thorsten Kampe
[EMAIL PROTECTED] wrote:
 * Shawn Milochik (Wed, 5 Nov 2008 12:28:46 -0500)
  Thanks, but either I'm missing something or you're missing
  something. I can't do any of what you describe on the machine I
  want to use sqlite on.
 
  I have downloaded the binary sqlite3 file from sqlite's Web site,
  and
 
  The linux binary will not work. You need the headers and the
  libraries. Grab the src tar ball and build and install locally.

 That is not correct. The binary *does* work, as I said last time.

 For the third time, it is not possible for me to build from source on
 that box.

 Sure you can. There are never permission problems for compiling - only
 for installing.

 And in any case, you keep talking about sqlite3, but I'm talking about
 pysqlite2.

 You (and Kurda) keep on talking the wrong stuff. First: you don't need
 pysqlite2. SQLite support is included in the latest Python as module
 sqlite3.

 If for whatever reason you need the latest SQLite module for Python
 (2.5.0), you can simply grab an rpm or build it from source and install
 it to your home directory. To build pysqlite you need the SQLite
 headers. If you can't install those to default path then simply grab the
 headers, put them somewhere into your home directory and tell the
 pysqlite build process where to find them.

 Thorsten


Okay, sorry if I haven't been specific enough. I don't know about the
original poster, but on the box I'm using, I don't have the latest
Python, the make command breaks because the system doesn't have the
proper libraries, and there is no sqlite3 module. I am not authorized
to fix any of that, and our support team isn't interested in helping
me because it's a Perl shop, not Python.

I'm not demanding that anyone solve my problem. I'm just asking if
there are files I can download and without compiling or building them
in any way, put them somewhere, point Python to that path, and be able
to use sqlite from Python. If the answer is no, it's no. I'm not
repeating myself because I enjoy it. For some reason everyone who has
answered me has ignored the basic question of whether this is possible
or not, so I have felt the need to reply and say so.

Thanks,
Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to build the pysqlite? Where to find the sqlite3.h?

2008-11-05 Thread Shawn Milochik
On Wed, Nov 5, 2008 at 8:52 PM, Kurda Yon [EMAIL PROTECTED] wrote:
 By the where can I find a simle tutorial about the work with the
 sqlite from the Python?
 --
 http://mail.python.org/mailman/listinfo/python-list


Once you get the connection, you can pretty much just do whatever if
you know SQL. Here's some working code from one of my little projects:

#!/usr/bin/env python

from pysqlite2 import dbapi2 as sqlite

import time
#import sys

sqliteDatabase = status.db

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS auctions (auction_id
INTEGER PRIMARY KEY, numBids INTEGER, currentPrice INTEGER, timestamp
TEXT(50), itemTitle TEXT(100))')
connection.close()

local = time.localtime()
timeStamp = %s-%02d-%02d_%02d:%02d % (local[0], local[1], local[2],
local[3], local[4])

def recordExists(auctionID):

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
cursor.execute('SELECT COUNT(auction_id) FROM auctions WHERE
auction_ID = ' + auctionID.__str__())
for row in cursor:
return row[0]

cursor.close()

connection.close()

def retrieveAuctionInfo(auctionID):
connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
cursor.execute('SELECT currentPrice, numBidsFROM auctions
WHERE auction_ID = ' + auctionID.__str__())
for row in cursor:
return [row[0],row[1]]

cursor.close()

def insertAuction(auctionID, currentPrice, currentBids, itemTitle):

itemTitle = itemTitle.replace('', '')

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
insertQuery = 'INSERT INTO auctions (auction_id, currentPrice,
numBids, timestamp, itemTitle) VALUES (%s, %s, %s, %s, %s)' %
(auctionID, currentPrice, currentBids, timeStamp, itemTitle)
cursor.execute(insertQuery)
connection.commit()

cursor.close()

connection.close()

def updateAuction(auctionID, currentPrice, currentBids):

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
updateQuery = 'UPDATE auctions SET currentPrice = %s, numBids =
%s, timestamp = %s WHERE auction_id = %s;' % (currentPrice,
currentBids, timeStamp,auctionID)
cursor.execute(updateQuery)
connection.commit()

cursor.close()
connection.close()

def getTotalAmount():

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
selectQuery = SELECT SUM(currentPrice) FROM  auctions WHERE numBids  0;
cursor.execute(selectQuery)
for row in cursor:
return float(row[0])

cursor.close()

connection.close()

def displayAuctions(sortBy=timestamp DESC):

connection = sqlite.connect(sqliteDatabase)
cursor = connection.cursor()
selectQuery =  SELECT auction_id, numBids, currentPrice,
timestamp, itemTitle FROM  auctions WHERE numBids  0 ORDER BY  +
sortBy + ;
cursor.execute(selectQuery)
for row in cursor:
auctionID, numBids, currentPrice, timestamp, itemTitle = row

print %25s $%6.2f (%2s bids) Last update: %16s %
(itemTitle[:25], currentPrice, numBids, timestamp)

cursor.close()

print 

connection.close()

if __name__ == __main__:
displayAuctions(currentPrice DESC)
displayAuctions()
#displayAuctions(numBids DESC)
print $%3.2f % getTotalAmount()
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to protect website from access without authentication?

2008-11-03 Thread Shawn Milochik
This isn't really a Python question -- it's a Web development
question. The easy answer is to just password protect the directory
all the pages are stored in, and require a password. This can be set
up using Apache or IIS.

If what you really meant to ask was how to prevent anyone from
accessing certain functionality, then you should look into using
sessions, and write the pages you're worried about to require an
authenticated session. This is better than the solution above for
several reasons: You can grant different levels of permission to
different users, you can revoke permission from some users while
allowing it for others, and you can allow your users to each have
their own password. Plus, you'll be able to log which user did what.

If this wasn't helpful, please be much more specific in restating your question.

Shawn



On Mon, Nov 3, 2008 at 8:30 AM, Good Z [EMAIL PROTECTED] wrote:
 Dear All,

 We are developing a website and would like to password protect the whole
 site.

 If any user visit our site using ip address or using the http link, he/she
 will be asked for login password and then granted the access to whole site
 based on the correct password. Help will be appreciated.

 Thank  Regards,
 Mike


 --
 http://mail.python.org/mailman/listinfo/python-list





-- 
http://i203.photobucket.com/albums/aa74/harrowlawl/sciencevsreligion.jpg
--
http://mail.python.org/mailman/listinfo/python-list


Re: PYTHON WORKING WITH PERL ??

2008-11-02 Thread Shawn Milochik
On Sat, Nov 1, 2008 at 11:15 AM, Nicola Larosa (tekNico)
[EMAIL PROTECTED] wrote:
 Pat [EMAIL PROTECTED] wrote:
 After you learn Python, you'll come to despise Perl.

 Some of us came to despise Perl *before* learning Python (third to
 last paragraph):

For what it's worth, I thought I'd throw in my 2¢. I used to like Perl
a whole lot. I was never a Perl Monk, or a guru of any kind. But Perl
is powerful and convenient. In fact, I still use Perl one-liners all
the time. For any quickie one-liner, especially involving regular
expressions, it's unparalleled as far as I know. But once I started
using Python, I immediately preferred it to Perl. Now, I'm useless in
Perl. To even write a simple script, I end up having to hit up Google
for the syntax. Things don't make sense, and it's awkward for me to
put my thoughts down in Perl code. Python, on the other hand, almost
always does what I was thinking of when I wrote it. Don't get me wrong
-- I still write bad code. But most of the issues are bugs with the
logic, when I don't do enough thinking before typing (which Python
makes so easy). I rarely struggle with any syntax issues at all.

The reason I think Python blows Perl away is that it makes it much
easier to read code after a period of time. Even if it's not your
code. With Perl, it's too easy to write code that you have to decipher
even after your lunch break. For more thoughts on these things from
someone much, much more qualified than I, check out this fantastic
article: http://www.linuxjournal.com/article/3882
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows DOS box redirection

2008-10-31 Thread Shawn Milochik
On Fri, Oct 31, 2008 at 2:14 PM, Bill McClain
[EMAIL PROTECTED] wrote:
 On 2008-10-31, Stef Mientki [EMAIL PROTECTED] wrote:
 Well I don't know any Windows users that still use DOS-boxes ;-)
 cheers,

 What do they do when they want to run a cross-platform command-line script
 with parameters and redirection?

 I suppose they could install cygwin and run bash, but that seems like overkill
 for what should be a simple task.


Easy. Make a desktop shortcut which includes the parameters, etc.
People do that all the time, including for GUI apps such as Internet
Explorer which have some optional command-line shortcuts.

The only thing you have to do is make sure that the Windows machine
associates files with the .py extensions with the Python interpreter.
The easiest way is to right-click a .py file, select Choose an
Application, select the Python runtime, and check the box for always
use this program.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Exact match with regular expression

2008-10-31 Thread Shawn Milochik
On Fri, Oct 31, 2008 at 8:57 PM, Lawrence D'Oliveiro
[EMAIL PROTECTED] wrote:
 In message [EMAIL PROTECTED], Rob
 Williscroft wrote:

 Read (and bookmark) this:

 http://www.python.org/doc/2.5.2/lib/re-syntax.html

 Funny how you never get a thank-you when you tell people to RTFM.
 --
 http://mail.python.org/mailman/listinfo/python-list



Hmmm. Kind of odd. Someone involved in the language they're having
trouble with wrote some documentation for the exact thing they're
asking for, you tell them where it is, and that doesn't deserve
thanks?

Something's wrong here. Well, it's about time for that which must be
read by everyone on the Internet to be mentioned again.

If you haven't read this yet, read this:
   http://www.catb.org/~esr/faqs/smart-questions.html

Especially if you have asked for help and not gotten what you wanted.
Especially if people ignore your questions.
Especially if people give answers that don't help you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not get environment variable when using cron.

2008-08-18 Thread Shawn Milochik
Here's a more English version of what people are trying to explain:

When you log into a Unix session, certain files in your home directory
are read and add environment variables to your session. When you run a
cron job, it does not do this. It still runs as you as far as
permissions go, but it is not identical to you typing the command in
an interactive session.

The easiest solution (in my opinion) is to write a bash script to
execute your Python script, and use that bash script to add those
environment variables. The most likely file you'll want to run is
.bashrc in your home directory. If you're on a Mac, it's .bash_login
instead.

Example:

#/usr/bin/env bash

source ~/.bashrc
path/my_script.py

Something like that should take care of it. If not, get creative --
add the env command to your bash script and have it send the output
to a file: env  cron_env.txt

Then run env in your interactive session and look for differences.

Shawn
--
http://mail.python.org/mailman/listinfo/python-list


Re: Testing for the first few letters of a string

2008-08-07 Thread Shawn Milochik
Check out the built-in string.startswith() method.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Monitor and compare two log files in real time

2008-08-06 Thread Shawn Milochik
Can you be more specific? That will also help you write your
requirements, which will lead to your pseudo code and then your code.

Do you want to search for a a pre-defined string (or set of strings),
or just look for anything matching a pattern to appear in the first
file? Related question: Can that string appear anywhere in the second
file, or does it have to appear in a certain pattern (at the beginning
of a line, followed by a colon or the word error or something?

Do the log entries have timestamps, or will you be capturing the time
your script found the string in file 1? What will you do if the script
must be restarted and forgets what it found in the past eight
minutes?

If you're feeling ambitious, write some code. Figure out how to:

1. Read a file.

2. Locate the value(s) you are looking for and retain them somehow.

Once you can do those two things, you can easily read the second file
and seek the values you already found. A few lines to handle the
eight-minute rule, and you're almost done.

Post back when you have some code written.

ShawnMilo
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing of a file

2008-08-06 Thread Shawn Milochik

 I would like to parse this file by extracting the field id, ra, dec and mjd
 for each line. It is
 not, however, certain that the width of each value of the field id, ra, dec
 or mjd is the same
 in each line. Is there a way to do this such that even if there was a line

Regular expressions will do the trick nicely.

 where Ra=** and
 MJD= was swapped it would be parsed correctly?


Yes, but you'll probably have to look at each line three times or
split it into a list and check the elements.


 Cheers
  Tommy
 --
 http://mail.python.org/mailman/listinfo/python-list



ShawnMilo
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finally had to plonk google gorups.

2008-04-30 Thread Shawn Milochik
How does one plonk stuff from Google Groups? Specifically, how
can this be done in Gmail?

Thanks,
Shawn
--
http://mail.python.org/mailman/listinfo/python-list

Re: Issue with regular expressions

2008-04-30 Thread Shawn Milochik
My stab at it:


My stab at it:

#!/usr/bin/env python

import re

query = ' some words  with and withoutquotes '

query = re.sub(\s+,  , query)


words = []

while query.__len__():

query = query.strip()
print(Current query value: '%s' % query)
print words
print

if query[0] == '':
secondQuote = query[1:].index('') + 2
words.append(query[0:secondQuote].replace('', '').strip())
query = query[secondQuote:]

else:
if query.count( ) == 0 :
words.append(query)
query = 
else:
space = query.index( )
words.append(query[0:space])
query = query[space:]

print words
print query
--
http://mail.python.org/mailman/listinfo/python-list

Checking for unique fields: performance.

2008-04-18 Thread Shawn Milochik
I'm looping through a tab-delimited file to gather statistics on fill rates,
lengths, and uniqueness.

For the uniqueness, I made a dictionary with keys which correspond to the
field names. The values were originally lists, where I would store values
found in that field. Once I detected a duplicate, I deleted the entire
element from the dictionary. Any which remained by the end are considered
unique. Also, if the value was empty, the dictionary element was deleted and
that field considered not unique.

A friend of mine suggested changing that dictionary of lists into a
dictionary of dictionaries, for performance reasons. As it turns out, the
speed increase was ridiculous -- a file which took 42 minutes to run dropped
down to six seconds.

Here is the excerpt of the bit of code which checks for uniqueness. It's
fully functional, so I'm just looking for any suggestions for improving it
or any comments. Note that fieldNames is a list containing all column
headers.

#check for unique values
#if we are still tracking that field (we haven't yet
#found a duplicate value).
if fieldUnique.has_key(fieldNames[index]):
#if the current value is a duplicate
if fieldUnique[fieldNames[index]].has_key(value):
#sys.stderr.write(Field %s is not unique. Found a
duplicate value after checking %d values.\n % (fieldNames[index], lineNum))
#drop the whole hash element
fieldUnique.__delitem__(fieldNames[index])
else:
#add the new value to the list
fieldUnique[fieldNames[index]][value] = 1
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python for mobiles

2008-01-31 Thread Shawn Milochik

A better solution would surely be to get a Nokia S60 'phone, for which 
there is a native Python implementation.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/



Steve:

Do you know if the Nokia E60i phone has this capability? Also, is wxPython 
supported?
Or are you just knowledgeable about the S60?

Thanks,
Shawn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sudoku solver in Python ...

2008-01-23 Thread Shawn Milochik

On Jan 23, 2008, at 10:02 PM, Derek Marshall wrote:

 This is just for fun, in case someone would be interested and because
 I haven't had the pleasure of posting anything here in many years ...

 http://derek.marshall.googlepages.com/pythonsudokusolver

 Appreciate any feedback anyone who takes the time to have a look would
 want to give ...

 Yours with-too-much-time-to-kill-on-the-train'ly,
 Derek
 --  
 http://mail.python.org/mailman/listinfo/python-list

For those interested in this topic, here's another (much shorter) one:

http://norvig.com/sudoku.html

I'm not making any judgements here, though. If anyone takes the time  
to actually review them, I'd be interested in hearing any educated  
comparisons.

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is python?????

2007-11-16 Thread Shawn Milochik
However, the python is not poisonous, so it is also edible if you can kill
one before it squeezes you to death. Despite this fact, it is not a major
food source for group members, due to our great respect for the mighty
python.

Shawn



On Nov 16, 2007 9:14 AM, Thorsten Kampe [EMAIL PROTECTED] wrote:

 * Cope (Fri, 16 Nov 2007 06:09:31 -0800 (PST))
  please tell me what is python.This group is so crowded.

 A Python is dangerous snake[1]. This group here mainly consists of
 misguided snake worshippers. You'd better run before they come to your
 place...

 Thorsten
 [1] http://en.wikipedia.org/wiki/Pythonidae
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Please read:
http://milocast.com/2007/07/31/this-i-believe/

A good reason not to say I don't know -- what do you want to do?
http://xkcd.org/330/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: What is python?????

2007-11-16 Thread Shawn Milochik
On Nov 16, 2007 2:16 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 On Nov 16, 8:14 am, Thorsten Kampe [EMAIL PROTECTED] wrote:
  * Cope (Fri, 16 Nov 2007 06:09:31 -0800 (PST))
 
   please tell me what is python.This group is so crowded.
 
  A Python is dangerous snake[1]. This group here mainly consists of
  misguided snake worshippers. You'd better run before they come to your
  place...
 
  Thorsten
  [1]http://en.wikipedia.org/wiki/Pythonidae

 Don't listen to him, he was joking.

 Python is short for Monty Python's Flying Circus,
 a British television comedy originally from 1969-1971
 (although movies, records, books and Broadway shows
 continue to the present). Read the documention,
 you'll see numerous references to spam (used in one
 of their famous routines) and other Pythonisms.

 Anyway, all the posting in this group is comedy.
 If you aren't getting it, run out and buy and study
 all the DVD's. When you've reached the point where
 you have The Argument Clinic dialogue memorized,
 come back here and all this will make sense.

 Just be careful, some of the Python routines aren't
 SUPPOSED to make sense (cabbage crates over the how's
 your father), that's the joke.
 --
 http://mail.python.org/mailman/listinfo/python-list




Actually, this answer is the true one, and should be considered
authoritative.

Thanks, mensanator.

P.S.
Another Python is a programming language invented by Guido van Rossum,
which he named after Monty Python. You can see a lot about that at
python.org.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python beginner!

2007-11-16 Thread Shawn Milochik
I completely support Wildemar. Lazy questions like that deserve absolutely
nothing.

I agree that cushioning the reply with a brief explanation of why that
question sucks would have helped the original poster, but he doesn't deserve
any effort from any of us until he has shown evidence of his own efforts.
Then he will find a lot of friendly help.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: New

2007-10-29 Thread Shawn Milochik
On 10/28/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi!
 Am new to Python and am looking for a sample project that demonstrates
 how to connect to MySQL, save data in MySQL database using a form on a
 web page.

 Regards,
 Joseph

 --
 http://mail.python.org/mailman/listinfo/python-list



1. Read this: http://catb.org/~esr/faqs/smart-questions.html

2. You can easily find what you're asking for on Google.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expression

2007-10-23 Thread Shawn Milochik
On 10/22/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi,

 I'm trying to learn regular expressions, but I am having trouble with
 this.  I want to search a document that has mixed data; however, the
 last line of every entry has something like C5H4N4O3 or CH5N3.ClH.
 All of the letters are upper case and there will always be numbers and
 possibly one .

 However below only gave me none.

 import os, codecs, re

 text = 'C:\\text_samples\\sample.txt'
 text = codecs.open(text,'r','utf-8')

 test = re.compile('\u+\d+\.')

 for line in text:
 print test.search(line)

 --
 http://mail.python.org/mailman/listinfo/python-list



I need a little more info. How can you know whether you're matching
the text you're going for, and not other data which looks similar? Do
you have a specific field length? Is it guaranteed to contain a digit?
Is it required to start with a letter? Does it always start with 'C'?
You need to have those kinds of rules in mind to write your regex.

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] matching a street address with regular expressions

2007-10-10 Thread Shawn Milochik
On 10/4/07, Ricardo Aráoz [EMAIL PROTECTED] wrote:
 Christopher Spears wrote:
  One of the exercises in Core Python Programming is to
  create a regular expression that will match a street
  address.  Here is one of my attempts.
 
  street =  1180 Bordeaux Drive
  patt = \d+ \w+
  import re
  m = re.match(patt, street)
  if m is not None: m.group()
  ...
  '1180 Bordeaux'
 
  Obviously, I can just create a pattern \d+ \w+ \w+.
  However, the pattern would be useless if I had a
  street name like 3120 De la Cruz Boulevard.  Any
  hints?
 


Also, that pattern can be easily modified to have any number of words
at the end:
patt = \d+ (\w+){1,}
This would take care of 3120 De la Cruz Boulevard.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] data from excel spreadsheet to csv and manipulate

2007-10-03 Thread Shawn Milochik
On 10/3/07, sacha rook [EMAIL PROTECTED] wrote:

 Hi

  can anyone help with the best way to tackle this?

  I have a spreadsheet ms excel, that has a name column that I want to
 extract to csv and manipulate as follows.

  The name column has data in this format

  Name

  Surname Firstname

  after extracting and manipulating I want it to be as follows in three comma
 separated fields;


  Firstname, Surname, Firstname Surname

  So

  Smith John

  becomes

  John, Smith, John Smith

  I hope I have explained myself.

  I want to use python to do all this if sensible, so what is the best
 approach?

  Many thanks

  S

 
 Do you know a place like the back of your hand? Share local knowledge with
 BackOfMyHand.com
 ___
 Tutor maillist  -  [EMAIL PROTECTED]
 http://mail.python.org/mailman/listinfo/tutor




Here's the best approach:

1. Browse: http://python.org/doc/

2. Search Google.

3. Write code.

4. Post code to the group and ask for help with the pieces that aren't
working as you expect.

Have fun!

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Algebraic Modules For Python

2007-10-02 Thread Shawn Milochik
On 10/1/07, Brandon McGinty [EMAIL PROTECTED] wrote:


 Hi All,
 I know that there is probably a great deal of literature on this on the net,
 but I don't have any time to go searching.

snip --

 Brandon McGinty
 McGinty Soft Ltd.
 Website design, configuration, and maintenance
 Python and PHP coder
snip

So let me get this straight:

You label yourself as a coder for hire in Python, but you don't have
time to search the Internet for an answer to your own Python question?

Remind me to avoid McGinty Soft for any and all needs which might
require someone useful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Take if offline

2007-09-25 Thread Shawn Milochik
Since everyone else is replying to the list, I'll (top) post this:

No, not really. He had to give everyone the rule once. Otherwise, he'd
have to do it a hundred times a day, and monitor every single post to
find out who he had to inform. He'd end up doing not much else with
his life, and would flee to a monastery and give up coding forever.
You wouldn't want that to happen, would you?




On 9/25/07, Michael Langford [EMAIL PROTECTED] wrote:
 I agree with Kent...

 --
 Michael Langford
 Phone: 404-386-0495
 Consulting: http://www.TierOneDesign.com/
 Entertaining:
 http://www.ThisIsYourCruiseDirectorSpeaking.com


 On 9/25/07, Kent Johnson [EMAIL PROTECTED] wrote:
  Hansen, Mike wrote:
   Anytime someone posts in HTML, or posts without a subject, or
   accidentally
   hijacks a thread, or top-posts, or writes in caps, a couple of posters
   pop up
   and complain. Rather than posting to the entire list, I think it'd be
   best if
   you send your complaint directly to the offending user. I'd prefer to
   read
   about Python not read lessons in net/mail-list etiquette.
 
  Hmmm. So instead, whenever someone complains about netiquette on-list we
  should post on-list complaining about it? I'm not sure that improves the
  situation any, especially if it sparks a discussion. Perhaps you should
  email your suggestion privately to the offending parties. :-)
 
  I definitely think this list is about how to be part of the Python
  community, as well as how to program in Python. Knowing how to
  participate in a mailing list is part of that. Maybe you could just skip
  those posts, there are not that many of them.
 
  Kent
  ___
  Tutor maillist  -  [EMAIL PROTECTED]
  http://mail.python.org/mailman/listinfo/tutor
 


 ___
 Tutor maillist  -  [EMAIL PROTECTED]
 http://mail.python.org/mailman/listinfo/tutor




-- 
Please read:
http://milocast.com/2007/07/31/this-i-believe/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding prime numbers

2007-09-20 Thread Shawn Milochik
On 9/20/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On Sep 19, 1:31 pm, Shawn Milochik [EMAIL PROTECTED] wrote:
   If you'd just search the archives, you would have found this:
 
  http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
 
  Yeah, but that's no fun. ;o)

 Yes! Never do what you can fool others into doing for you.

 Mike


Maybe for some people, but for me it's more fun to figure it out on my
own. By the no fun part, I meant that it wouldn't be fun to just
find the answer in an old thread instead of writing code to find
primes myself.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Finding prime numbers

2007-09-19 Thread Shawn Milochik
Here's my attempt:

#!/usr/bin/env python

import math

for x in range(3,1000,2):

isPrime = True

for y in range(3,(math.sqrt(x) + 1)):
if x % y == 0:
isPrime = False
break

if isPrime:
print %d is prime. % x

Notes: This doesn't bother with even numbers at all, and uses the
square root function of math.

Any improvements anyone?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Finding prime numbers

2007-09-19 Thread Shawn Milochik
Okay, I caught one bug already myself:

 for y in range(3,(math.sqrt(x) + 1)):

should be

for y in range(3,(int(math.sqrt(x)) + 1)):
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding prime numbers

2007-09-19 Thread Shawn Milochik
 If you'd just search the archives, you would have found this:

 http://groups.google.com/group/comp.lang.python/browse_thread/thread/b134b2235e9c19a6/34857fb0b0b2a4b5?lnk=gstq=prime+numberrnum=1#34857fb0b0b2a4b5


Yeah, but that's no fun. ;o)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question

2007-09-18 Thread Shawn Milochik
On 9/18/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On Sep 18, 1:31 pm, Shawn Milochik [EMAIL PROTECTED] wrote:
  On 9/18/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 
   If I have a file name: AVC1030708.14.  How do I strip out certain
   characters from the file name?  I am so used to using MID, LEFT, and
   RIGHT functions, that I have no idea how to do this in python?  I have
   had trouble as well with most newbies on finding the help.  But I have
   used the command line built in help, but with no luck.  Thanks.
 
   Kou
 
  Do you want to strip out specific characters, characters in specific
  positions, or characters matching certain patterns?

 Yes, I want specific characters in specific positions.


Try this:

newString = oldString[0:3] + oldString[5:10]

Some other quick examples:

 test = this is a test
 test
'this is a test'
 fred = test[:3] + test[9:]
 fred
'thi test'
 test[0:5]
'this '
 test[:5]
'this '
 test[4:]
' is a test'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question

2007-09-18 Thread Shawn Milochik
On 9/18/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 If I have a file name: AVC1030708.14.  How do I strip out certain
 characters from the file name?  I am so used to using MID, LEFT, and
 RIGHT functions, that I have no idea how to do this in python?  I have
 had trouble as well with most newbies on finding the help.  But I have
 used the command line built in help, but with no luck.  Thanks.

 Kou


Do you want to strip out specific characters, characters in specific
positions, or characters matching certain patterns?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pattern combinations

2007-09-17 Thread Shawn Milochik
On 9/17/07, dorje tarap [EMAIL PROTECTED] wrote:
 Hi all,

  Given some patterns such as ...t...s. I need to make all possible
 combinations given a separate list for each position. The length of the
 pattern is fixed to 9, so thankfully that reduces a bit of the complexity.

  For example I have the following:

  pos1 = ['a',' t']
  pos2 = ['r', 's']
  pos3 = ['n', 'f']

  So if the pattern contains a '.' character at position 1 it could be 'a' or
 't'. For the pattern '.s.' (length of 3 as example) all combinations would
 be:

  asn
  asf
  tsn
  tsf

  Thanks
 --
 http://mail.python.org/mailman/listinfo/python-list



Sounds like homework to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Start

2007-09-14 Thread Shawn Milochik
On 9/14/07, James Stroud [EMAIL PROTECTED] wrote:

 Here's your recipe:

1. begin coding until you hit a wall
2. read official tutorial until you figure out a solution
3. experiment in interactive interpreter
4. goto 1.

 I know this sounds obvious, but its the best way to jumpstart.

 James
 --

What a beautiful way of putting it! That's what I do all the time,
although sometimes my bookshelf or Google is a stand-in for #2. I try
not to post to the list before I have working code.

You know, if you could make that process into a haiku, you could just
make that your sig and answer nearly every question that hits this
list. ^_^

I wonder whether lists like this hurt more people than they help,
because it's too easy to ask for help too soon. Those of you who
consistently  give the best advice didn't learn by asking for help
every step along the way, did you? Is it really teaching a man to fish
if you bait his line and tell him where to cast?

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Just bought Python in a Nutshell

2007-09-14 Thread Shawn Milochik
My best advice:

Skim it -- just flip the pages, glancing at each one without really
reading it -- maybe just read the bold type. You'll find that very
rewarding when you run into a problem in your coding and remember that
you saw *something* which could be related. You will probably notice
some built-in functions that you will need and possibly would have
re-invented if you didn't know they were there.

I don't really find it to be a reading book -- it's more of a
reference book. Flip through it, then keep it within reach of your
keyboard.

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] list iteration question for writing to a file on disk

2007-09-14 Thread Shawn Milochik
When you use print, it automatically adds a newline (\n).

You can avoid this by following the print line with a comma:

print j,

Or rstrip() the line before printing. Either way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between two times (working ugly code, needs polish)

2007-09-12 Thread Shawn Milochik
 Just to be picky - your function returns the number of days between
 two dates, but it's called isOld, which looks like it should return a
 boolean.  i.e.  it looks like it would be used as:

 if not isOld(auctionDate, currentTime):
 checkForBid()

 rather than how I assume it is used:

 if isOld(auctionDate, currentTime) = 10:
 checkForBid()

 I'd call it daysDiff or something similar, or make it more specific so
 that it works like the first block of code above:

You're absolutely right; I started writing it with one purpose in mind
and changed it midstream. I actually renamed it yesterday to dayDiff.
;o)

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Difference between two times (working ugly code, needs polish)

2007-09-11 Thread Shawn Milochik
I have done what I wanted, but I think there must be a much better way.

Given two timestamps in the following format, I just want to figure
out how far apart they are (in days, seconds, whatever).

Format:

-MM-DD_MM:SS

Example:
2007-09-11_16:41


It seems to me that to do what I want, I need to convert a string into
a number (time.mktime()), such as this: 1189543487.0

Once I have that, I can just subtract one from the other and do
whatever I want. The ugly part is converting something like
2007-09-11_16:41 to the numeric equivalent.

Below is my code. Any suggestions?

Thanks in advance.


Here is what I have (works):

#runTimeStamp is the current time, set when the script begins execution
def recAge(lastUpdate, runTimeStamp):

import re

oneDay = 60 * 60 * 24

lastUpdate = re.sub(r'\D+', ',', lastUpdate)
lastUpdate = lastUpdate + ,0,0,0,0
lastUpdate = [int(x) for x in lastUpdate.split(',')]
lastUpdate = time.mktime(tuple(lastUpdate))

runTimeStamp = re.sub(r'\D+', ',', runTimeStamp)
runTimeStamp = runTimeStamp + ,0,0,0,0
runTimeStamp = [int(x) for x in runTimeStamp.split(',')]
runTimeStamp = time.mktime(tuple(runTimeStamp))

return (runTimeStamp - lastUpdate) / oneDay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between two times (working ugly code, needs polish)

2007-09-11 Thread Shawn Milochik
On 9/11/07, Grant Edwards [EMAIL PROTECTED] wrote:
 On 2007-09-11, Shawn Milochik [EMAIL PROTECTED] wrote:

  I have done what I wanted, but I think there must be a much better way.

 See the strptime() function in either the time or the datetime
 modules:

 http://docs.python.org/lib/module-time.html
 http://docs.python.org/lib/module-datetime.html



Grant:

Thanks, this works, and is much shorter. Any further improvements, anyone?

def isOld(lastUpdate, runTimeStamp):

   oneDay = 60 * 60 * 24

   lastUpdate = time.mktime(time.strptime(lastUpdate, %Y-%m-%d_%H:%M))
   runTimeStamp = time.mktime(time.strptime(runTimeStamp, %Y-%m-%d_%H:%M))

   return (runTimeStamp - lastUpdate) / oneDay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between two times (working ugly code, needs polish)

2007-09-11 Thread Shawn Milochik

 I suppose really oneDay should be a global (i.e. outside the function
 definition). Apart from that it would be hard to improve on: obvious,
 easy to read, in short - pythonic.

 Are you concerned about daylight savings? That could certainly introduce
 a whole new level of complexity into the problem. Let's hope not ...

I'm not concerned with DST; this is a script which checks my Ebay
auctions (I have some things for sale), and sends me e-mail whenever
someone bids. It's run by cron every half hour -- it keeps me from
compulsively checking my auctions. ^_^

In any case, DST isn't an issue because the same machine generates
both timestamps, and all I use it for is to stop displaying auctions
after they are 10 days old, so I don't get all my old crap filling up
the alert e-mail or skewing the total dollar amount for all active
auctions.

Thanks.
Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Cron

2007-09-07 Thread Shawn Milochik
Could you send the output of crontab -l and the script you're running?

It's probably an environment issue of some kind, but it's hard to say
what blindly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why should I learn python

2007-09-07 Thread Shawn Milochik
I wholeheartedly second the recommendation of this article:

http://www.linuxjournal.com/article/3882
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Cron

2007-09-07 Thread Shawn Milochik
Any chance your import statements aren't coming in properly due to
something in your environment in Python that's not being inherited by
your cron job?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Text processing and file creation

2007-09-06 Thread Shawn Milochik
Here's my solution, for what it's worth:

#!/usr/bin/env python

import os

input = open(test.txt, r)

counter = 0
fileNum = 0
fileName = 

def newFileName():

global fileNum, fileName


while os.path.exists(fileName) or fileName == :
fileNum += 1
x = %0.5d % fileNum
fileName = %s.tmp % x

return fileName


for line in input:

if (fileName == ) or (counter == 5):
if fileName:
output.close()
fileName = newFileName()
counter = 0
output = open(fileName, w)

output.write(line)
counter += 1

output.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


PythonAlley.com

2007-09-05 Thread Shawn Milochik
I bought the domain PythonAlley.com (and PerlAlley.com and
RubyAlley.com) not too long ago. I had the inspiration to make some
kind of community site thing, but never did get around to it.

Does anyone have any ideas as to what a wonderful use for
PythonAlley.com would be? I'd really like to do something with at
least the Python site, since I love Python. Not too sure about the
others -- maybe I'm make them wikis and open them up to the community.
Maybe I should just sell them.

Ideas?

Thanks,
Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PythonAlley.com

2007-09-05 Thread Shawn Milochik
On 9/5/07, O.R.Senthil Kumaran [EMAIL PROTECTED] wrote:
 * Shawn Milochik [EMAIL PROTECTED] [2007-09-05 10:27:08]:
  I bought the domain PythonAlley.com (and PerlAlley.com and
 
  Does anyone have any ideas as to what a wonderful use for
  PythonAlley.com would be? I'd really like to do something with at

 If you don't have an idea, most likely others wont have as well. :)

 --
 O.R.Senthil Kumaran
 http://uthcode.sarovar.org


Faulty logic. Otherwise, you would have to agree that you don't know
what you want for lunch if I don't know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: REGULAR EXPRESSION

2007-09-05 Thread Shawn Milochik
 Hi.. Thanks alot for finding time to help a beginner like me. What I
 am trying to do is validate the input i get. I just want to take
 numbers and numbers only. So if the input is 23+1 or 2/3 or 9-0 or
 7/0 , I want to find it using reg exp. I know there are other ways to
 do this... but i thought i will try this as i need to learn reg exp. I
 tried \D+   ,   \W+,  and \D+|\W+ .. Thanks once again...


 --


Send a couple of strings and the output you would like from each.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Text processing and file creation

2007-09-05 Thread Shawn Milochik
On 9/5/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 I have a text source file of about 20.000 lines.
 From this file, I like to write the first 5 lines to a new file. Close
 that file, grab the next 5 lines write these to a new file... grabbing
 5 lines and creating new files until processing of all 20.000 lines is
 done.
 Is there an efficient way to do this in Python?
 In advance, thanks for your help.



I have written a working test of this. Here's the basic setup:




open the input file

function newFileName:
generate a filename (starting with 1.tmp).
If filename exists, increment and test again (0002.tmp and so on).
return fileName

read a line until input file is empty:

test to see whether I have written five lines. If so, get a new
file name, close file, and open new file

write line to file

close output file final time


Once you get some code running, feel free to post it and we'll help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Code reading for learning Python

2007-09-04 Thread Shawn Milochik
I second the Python Cookbook recommendation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Asking all python programmers.

2007-08-28 Thread Shawn Milochik
On 8/27/07, Lamonte Harris [EMAIL PROTECTED] wrote:
 Okay,  I know you've guys told me millions of times to read the manual I've
 read a lot of it.  What do you recommend studying the most? Python is my
 goal for the next year in the half. :)

 --
 http://mail.python.org/mailman/listinfo/python-list


Some notes on your question:

You've guys is nonsensical.
Your first sentence is a run-on sentence.
Your e-mail address identifies you as an immature script-kiddie.
Year in the half is nonsensical.

Okay, so why am I picking on you? Because I want to help. Present
yourself in this way, and you're not going to get as much help from
intelligent people as you would if they saw you were worth their time.

You are either going to get angry at me or you're going to think about
this. If you're angry then I can't help you. If you actually care how
people see you, you will get further in life in general.

To answer the question I think you were trying to ask, a combination
of The Python Cookbook and Dive Into Python should get you started
in doing amazing things with Python. The latter is available for free
online.

Take some pride in the way you write. It will pay off.

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I Need help from all the group participants

2007-08-21 Thread Shawn Milochik
Please enter John's heart rate.

Please notify me immediately if John's heart rate drops below 60 or
exceeds 100.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Shawn Milochik
#!/usr/bin/env python

normalPay = 0.4
overPay = 1.4
normalLimit = 22

def calcPay(numStops):

pay = 0

if numStops  normalLimit:
pay = overPay * (numStops - normalLimit)
numStops = normalLimit

return pay + (numStops * normalPay)

if __name__ == __main__:

print Pay for 1 stops: %.2f. % calcPay(1)
print Pay for 10 stops: %.2f. % calcPay(10)
print Pay for 17 stops: %.2f. % calcPay(17)
print Pay for 25 stops: %.2f. % calcPay(25)
print Pay for 30 stops: %.2f. % calcPay(30)
print Pay for 31 stops: %.2f. % calcPay(31)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Shawn Milochik
On 8/20/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On Aug 20, 9:23 am, HD1956 [EMAIL PROTECTED] wrote:
  This is probably a simple code. I am a truck driver who gets paid by
  stops and cases. I am trying to figure out how to code my stop pay. I
  get 40 cents per stop up to 22 stops, and $1.40 per stops after that.

 def calc(num):
 if num  23:
 return 0.4 * num
 else:
 overtime = num - 22
 x = 0.4 * 22
 x += overtime * 1.4
 return x

 # Use your own brain next time

 Mike

 --
 http://mail.python.org/mailman/listinfo/python-list





Mike,

I wonder if we were both just duped into helping someone with their homework...

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Shawn Milochik
 I like to write code, so it's not a big deal when it's something so
 simple. Still, that is beyond dumb! Nice code, by the way.

 Mike

Yeah, it was fun to write anyway. Thanks for the compliment on the
code. I still consider myself a Python newbie, so it's good to know
I'm not trying to write it like Perl or VBScript anymore. ^_^

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression dictionary search

2007-08-20 Thread Shawn Milochik
#!/usr/bin/env python

import re

patterns = { 'sho.' : 6, '.ilk' : 8, '.an.' : 78 }

def returnCode(aWord):
for k in patterns:
p = ^%s$ % k
regex = re.compile(p)
if re.match(regex, aWord):
return patterns[k]

if __name__ == __main__:

print The return for 'fred' : %s % returnCode('fred')
print The return for 'silk' : %s % returnCode('silk')
print The return for 'silky' : %s % returnCode('silky')
print The return for 'hand' : %s % returnCode('hand')
print The return for 'strand' : %s % returnCode('strand')
print The return for 'bank' : %s % returnCode('bank')


Note: If a word matches more than one pattern, only one will be returned.

I'm not sure if I'm doing the patterns thing properly -- if anyone
could instruct me on whether it would be proper to declare it in the
function, or use a global declaration, please let me know. However, it
runs properly as far as I tested it.

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question

2007-08-20 Thread Shawn Milochik
snip
 And Shawn, I didn't post any of my work because the network I work on
 isn't
 connected to the internet. So it didn't seem constructive to re-type
 all of my
 failed code just to satisfy your standards of proving that I've been
 trying to
 hack this myself for the past few days. All in all, thanks for your,
 u,
 constructive comments.

 --
 http://mail.python.org/mailman/listinfo/python-list



Your original post said clearly that you didn't post your code because
it didn't work. That's a completely different reason/excuse than no
Internet connection so I didn't want to re-type it. So either you're
lying or lazy, and in either case I don't appreciate your snarky
comments about my uhhh constructive comments.

Don't get me wrong -- I'm not saying you're definitely being
dishonest, but you have to admit that the appearance you gave is
questionable, and questionable behavior on lists like this gets
questioned.

Just so this isn't interpreted badly and doesn't start a flame-war, I
will just give up and say that if there was a misunderstanding it was
on my end, and I apologize. I just wanted to respond to your
passive-aggressive attack, since I'm a friendly, helpful person and
don't want to be unfairly labled as uhhh constructive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression dictionary search

2007-08-20 Thread Shawn Milochik
On 8/20/07, Paul McGuire [EMAIL PROTECTED] wrote:
 On Aug 20, 10:35 am, Shawn Milochik [EMAIL PROTECTED] wrote:
  #!/usr/bin/env python
 snip
  if __name__ == __main__:
 
  print The return for 'fred' : %s % returnCode('fred')
  print The return for 'silk' : %s % returnCode('silk')
  print The return for 'silky' : %s % returnCode('silky')
  print The return for 'hand' : %s % returnCode('hand')
  print The return for 'strand' : %s % returnCode('strand')
  print The return for 'bank' : %s % returnCode('bank')
 

 Shawn -

 All that copy/pasting has got to have carpal tunnel written all over
 it - DRY!

 tests = fred silk silky hand strand bank.split()
 for test in tests:
 print The return for '%s' : %s % (test, returnCode(test))

 -- Paul

 --
 http://mail.python.org/mailman/listinfo/python-list



You're right. Thanks for the correction. My wrists are shot as it is,
and it's easy enough in vim to copy  paste. You know how it is -- I
made one test line, then copied it to a second, then copied it to a
third... Guilty of not planning ahead. ;o)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I Need help from all the group participants

2007-08-20 Thread Shawn Milochik
On 8/20/07, Boris Ozegovic [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:

  The only sentence that comes to mind is:
 
  I hope I never find myself in a hospital that uses your system.

 You are not funny. The system isn't for hospitals, it is for university
 purposes.

 --
 Ne dajte da nas lažljivac Bandić truje:
 http://cnn.blog.hr/arhiva-2007-06.html#1622776372
 --
 http://mail.python.org/mailman/listinfo/python-list



I disagree. He is funny. Sorry you can't appreciate the humor -- it
must be the language barrier.

Lighten up and enjoy this life -- it's the only one we have.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >