Re: Compare list entry from csv files

2012-11-30 Thread Anatoli Hristov
> Can you print ex_phone first. You are opening the files in text mode
> so I wonder if the line endings are causing you to read and extra
> "line" in between. Can you try reading the csv as "rb" instead of
> "rt"?

Yes I did this: use the global list PHONELIST and opening the CSV in
binary - it works now

Thanks

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


Re: Compare list entry from csv files

2012-11-30 Thread Anatoli Hristov
> As I said before, process both files into lists, one that you treat as
> constant (and therefore capitalized) and the other containing the data
> you intend to modify.
>
> It'd be much cleaner if you did all that input file parsing stuff in one
> function, returning only the lists.  Call it just before calling
> name_find().  Similarly, the part you have at the end belongs in a
> different function, called just after calling name_find().
>
> There's lots of other stuff that should be cleaner, but you've ignored
> nearly all the suggestions from various people.

I'm not ignoring anything I just need more time :) I will clean all up
and will keep you updated - I promise


Regards

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


Re: amazing scope?

2012-11-30 Thread Jean-Michel Pichavant
- Original Message -
> I wrote a script, refactored it and then introducing a bug as below:
> 
> def record_things():
> out.write("Hello world")
> 
> if __name__ == '__main__':
> with open('output', 'w') as out:
> record_things()
> 
> 
> but the shocking thing is that it didn't actually stopped working, it
> still works perfectly!
> 
> What my explanation might be is that the "out" is declared at module
> level somehow,
> but that's not really intuitive and looks wrong, and works both on
> Python 2.7 and 3.2..
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

>From what I understand from the with documentation 
>http://docs.python.org/2/reference/compound_stmts.html#with

The with block has nothing to do with scopes. It does not define the target 
within that block, well, actually it does but it defines it for the current 
scope.
The with block only identifies where to call __enter__ and __exit__.

So I would say that "with open('output', 'w') as out" assignes "out" at the 
module level.

You may have been mislead by some other languages where a with block purpose is 
to limit the scope of a variable.

JM



-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: amazing scope?

2012-11-30 Thread Jean-Michel Pichavant


- Original Message -
> 2012/11/30 andrea crotti :
> 
> Already changing it to:
> 
> def record_things():
> out.write("Hello world")
> 
> def main():
> with open('output', 'w') as out:
> record_things()
> 
> if __name__ == '__main__':
> main()
> 
> makes it stops working as expected, so it's really just a corner case
> of using the if __name__ == '__main__'
> which I had never encountered before..

You do realize that 

foo = 5 # define at the module level

if __name__ == '__main__':
bar = 6 # also at the module level

if True:
ham = 8 # still at the module level

def func()
# scope has changed, only at the func level
jam = 9

Nothing magic about if __name__ == '__main__'

Cheers,

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: amazing scope?

2012-11-30 Thread Ulrich Eckhardt

Am 30.11.2012 12:11, schrieb andrea crotti:

I wrote a script, refactored it and then introducing a bug as below:

def record_things():
 out.write("Hello world")


This is a function. Since "out" is not a local variable, it is looked up 
in the surrounding namespace at the time the function is called.




if __name__ == '__main__':
 with open('output', 'w') as out:
 record_things()


This is not in a function, so binding variables affects the containing 
namespace. This includes binding the context manager to "out". Note that 
you could have moved the whole code into a function (e.g. one called 
main()) and then you would have gotten the expected failure.




What my explanation might be is that the "out" is declared at module
level somehow, but that's not really intuitive and looks wrong, and
works both on Python 2.7 and 3.2..


Other than in C/C++/Java and others, indention doesn't introduce a new 
scope, but I understand your intuition. Even simpler, this is how my 
early Python code looked like, in the absence of the C ternary operator 
and the distinction between a variable declaration and an assignment:


 foo = None
 if some_condition:
 foo = 'bar'
 else:
 foo = 'baz'

More idiomatic would have been this:

 if some_condition:
 foo = 'bar'
 else:
 foo = 'baz'


Summary: I'd say that everything is fine. ;)

Uli

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


Re: amazing scope?

2012-11-30 Thread Chris Angelico
On Sat, Dec 1, 2012 at 3:05 AM, andrea crotti  wrote:
> Well I knew that this works fine, even if I feel a bit guilty to do
> this, and better is:
>
> foo = 'bar' if some_condition else 'baz'
>
> Anyway for me the suprise is that something that is defined *later* at
> the module scope is found in a function which is defined *earlier*.

It's assigned to earlier. It's no different from C code like this:

int foo;

void blah()
{
/* do stuff with foo */
}

int main()
{
foo = 1;
}


In Python, the "int foo;" is implicit, but the scope is the same.

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


Re: amazing scope?

2012-11-30 Thread Jean-Michel Pichavant
- Original Message -
> Well I knew that this works fine, even if I feel a bit guilty to do
> this, and better is:
> 
> foo = 'bar' if some_condition else 'baz'
> 
> Anyway for me the suprise is that something that is defined *later*
> at
> the module scope is found in a function which is defined *earlier*.
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

What really matters for function is when they're executed, not defined (except 
for their parameter default value).

foo = 'I am foo'
bar = 'I am bar'

def funcA(param1=foo):
print param1
print bar

foo = 'I am another foo'
bar = 'I am another bar'

def funcB(param1=foo):
print param1
print bar

funcA()
funcB()

   


I am foo
I am another bar
I am another foo
I am another bar


cheers,

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen and the subprocess module

2012-11-30 Thread emile

On 11/29/2012 10:39 AM, Nobody wrote:



Every time I see your posts "Shanghai Noodle Factory" sticks in my head 
as my daily hummer.  :)






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


Re: Migrate from Access 2010 / VBA

2012-11-30 Thread emile

On 11/29/2012 02:46 AM, Nicolas Évrard wrote:


I'd like to add to the list
Tryton http://www.tryton.org/

Which framework can be used to create a business application 


Let me second this, although for openERP (the parent from which
Tryton was forked)...


Reporting is done through relatorio (http://relatorio.openhex.org/),
which uses ODF templates to generate ODF reports (or other format
thanks to unoconv) the client is written in GTk (we're writing one in
JavaScript right now (and I miss python badly)).


... for which the web client is fully up and running.

In any case it's a rich environment for business applications.

Emile




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


RE: amazing scope?

2012-11-30 Thread Prasad, Ramit
andrea crotti
> 
> I wrote a script, refactored it and then introducing a bug as below:
> 
> def record_things():
> out.write("Hello world")
> 
> if __name__ == '__main__':
> with open('output', 'w') as out:
> record_things()
> 
> 
> but the shocking thing is that it didn't actually stopped working, it
> still works perfectly!
> 
> What my explanation might be is that the "out" is declared at module
> level somehow,
> but that's not really intuitive and looks wrong, and works both on
> Python 2.7 and 3.2..

Makes sense to me. `out` is declared in an if statement. If statements
have no "scope" and it is not in a function so it gets added to the 
module's namespace.


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: pyHook and time libraries

2012-11-30 Thread Prasad, Ramit
Doron wrote:
> 
> Hey, I'm tring to create a software that records the keyboard/mouse and sends 
> email of the log every
> predetermined period.
> 
> I've manage to make the recorder and the auto-email sender, but I still can't 
> make both of them work
> simultaneously.
> 
> Can someone help me with this please?
> I thought about threading but again... It just sends blank mails without the 
> logs.
> 
> Thanks alot ahead!

I am not sure how to even begin helping you. I do not even know
what is wrong other than "can't make both of them work simultaneously".
What version of Python and OS? Are you using any 3rd party modules?
What is the code you use? What happens and what do you expect? How
are you getting the logs for email? Are they being passed in or are
you using a log file?


~Ramit



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Textmining

2012-11-30 Thread subhabangalore
Dear Group,
Python has one textming library, but I am failing to install it in Windows.
If any one can kindly help.
Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: please help me to debud my local chat network program

2012-11-30 Thread Prasad, Ramit
Minh Dang wrote:
> 
> can anyone help me?

Chris Angelico has given you some good comments which
should give you a direction to investigate.

This list is a global list and you seem a tad impatient. It is normal
to hear back from a few hours to a day or two. 

Even if I wanted to help, without context in this email I might not
know what you need help with. I could probably look it up in an 
archive of the list, but it is unlikely I will. Help yourself
by keeping relevant text in the email and respond inline (or below)
the quoted text. 

That being said, did Chris's suggestion work? If not what happened?


~Ramit




This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


send email with bcc

2012-11-30 Thread Ed
Hi,

I have found many different suggestions on "how to" code python to send a bcc 
email. None of which have worked in my environment - yet. Following is what I 
have at this time, which is erroring. Most of the code I've found will 
successfully send the message to the TO & CC recipients, but not the BCC. Any 
help is very much appreciated. Thx, Ed .


from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP

to = 'e...@domain.gov'
cc = 'e...@gmailmail.com'
bcc = 'e...@domain.net'
sender = 'edsb...@domain.gov'

msg = MIMEMultipart()
msg['To'] = to
msg['Cc'] = cc
msg['Subject'] = 'Monthly Report'
msg['From'] = sender

smtp = SMTP("smtp.server.com")
# Start the server:
smtp.ehlo()

# Send the email
smtp.sendmail(sender, [to] + bcc, msg.as_string())

The above generates the following error:
Traceback (most recent call last):
  File "/opt/batch/ebtest/example4.py", line 46, in 
smtp.sendmail(sender, [to] + bcc, msg.as_string())

Other iterations of the code have worked without error, but do not send mail to 
the BCC recipient.

Thanks in advance for any assistance!
~Ed
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: send email with bcc

2012-11-30 Thread Tim Golden

On 30/11/2012 20:25, Ed wrote:

to = 'e...@domain.gov'
bcc = 'e...@domain.net'


[... snippage ...]


smtp.sendmail(sender, [to] + bcc, msg.as_string())


Well, you crucially don't show us the rest of the traceback. But I 
imagine you'd have got something like this:




ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit 
(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> to = 'e...@domain.gov'
>>> bcc = 'e...@domain.net'
>>> [to] + bcc
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can only concatenate list (not "str") to list
>>>



which suggests, fairly clearly, that you're trying to concatenate a 
string and a list.


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


Re: send email with bcc

2012-11-30 Thread Ervin Hegedüs
Hello,

On Fri, Nov 30, 2012 at 12:25:37PM -0800, Ed wrote:
> 
> # Send the email
> smtp.sendmail(sender, [to] + bcc, msg.as_string())
> 
> The above generates the following error:
> Traceback (most recent call last):
>   File "/opt/batch/ebtest/example4.py", line 46, in 
> smtp.sendmail(sender, [to] + bcc, msg.as_string())

didn't you forgot to attach the reason of the error, I mean what
is the Exception type?

> Other iterations of the code have worked without error, but do not send mail 
> to the BCC recipient.

you could't concatenate a list and a string at this way.

You can do that one of these:

l = ['foo']
s = 'bar'

l.append(s)

or

n = l+[s]


a.
 

-- 
I � UTF-8
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Textmining

2012-11-30 Thread Neil Cerutti
On 2012-11-30, subhabangal...@gmail.com  wrote:
> Python has one textming library, but I am failing to install it
> in Windows. If any one can kindly help.

More information needed.

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


Re: send email with bcc

2012-11-30 Thread Ed
Oops. Sorry 'bout that. I somehow didn't grab the entire traceback info. Well, 
turns out one if not more of my BCC attempts is working. Just thought to check 
my spam filter of the BCC email address and there are quite a few messages in 
there. I've got it working now.

Thanks to you both for the quick responses!!
~Ed
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: amazing scope?

2012-11-30 Thread Dave Angel
On 11/30/2012 11:05 AM, andrea crotti wrote:
> Well I knew that this works fine, even if I feel a bit guilty to do
> this, and better is:
>
> foo = 'bar' if some_condition else 'baz'
>
> Anyway for me the suprise is that something that is defined *later* at
> the module scope is found in a function which is defined *earlier*.

It would have been nice if you had indicated in your original post just
*what* you considered "shocking" about the code sample.  The code was
valid, and we all had to guess what about it was puzzling you.  Like
most others, I first guessed you were confused about the definition
being in an if statement.  Then I thought you were confused by the with
statement, since it's not as obvious that "as" binds the name to the
object in the same way as assignment.

But I never would have guessed that you were confused about the order of
execution in a module.

The source code in a module is executed in order, including function
definitions defined at top level.  However, such a function definition's
execution creates a function object, and assigns a global name (usually)
to that object.  It does not "execute" the object.  When that function
is executed later, it then looks for global variables for stuff that's
not defined within its own scope.  So by the time the function
references the 'out' name, it's been successfully added to the global
namespace.



-- 

DaveA

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


Re: Textmining

2012-11-30 Thread Dave Angel
On 11/30/2012 02:48 PM, subhabangal...@gmail.com wrote:
> Dear Group,
> Python has one textming library, but I am failing to install it in Windows.
> If any one can kindly help.
> Regards,
> Subhabrata.

Please think about what you're asking, if you want people to help you. 
You say Python has a testming library,  But CPython's standard library
version 3.3 does NOT have a library called testming.  Neither does 2.7
in case you're running that one.  Now, maybe some other version of
Python has other stuff in its standard library, or maybe it's only
available on the Amiga port of python.  But you give no clues to which
one it was.

I repeated the search with a keyword of testmining, in case that's the
actual name of the library.  Still in neither 2.7 nor 3.3.

So I'm forced to gaze even closer into my crystal ball.  How about

http://scripts.downloadroute.com/textmining-95300f9f.html
http://www.testmine.com/
http://webscripts.softpedia.com/script/E-Commerce/Catalogs/textmining-66084.html
http://www.christianpeccei.com/projects/textmining/
http://pybrary.net/pyPdf/
http://code.activestate.com/recipes/511465/
http://www.unixuser.org/~euske/python/pdfminer/index.html

http://orange.biolab.si/
http://www.amazon.com/Python-Text-Processing-NLTK-Cookbook/dp/1849513600?tag=duckduckgo-d-20
http://linux.softpedia.com/get/Utilities/textmining-61802.shtml
http://pypi.python.org/pypi/textmining
http://orange-text.readthedocs.org/en/latest/


I could call a mechanic, and tell him my car makes a funny nose, and no
matter how hard I kick the right front tire the noise doesn't go away,
and he's unlikely to be able to help.  He'd probably like some
fundamental facts about the problem.  So do we.

What version of Windows OS are you running?
What version of what implementation of Python are you running?
What library, located at what URL did you try to install?
How did you try the installation?  What happened?  How did you know you
failed?

In many of these answers, you should paste actual program output rather
than paraphrasing.  Certainly, if you got an exception, you should paste
the entire stack trace.  And if you got that far, a minimal code example
that shows the problem.

-- 

DaveA

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