[Tutor] Problem importing pandas library

2018-05-27 Thread Bhavna Soni
I installed pandas library using pip9. I get errors while importing
it, Uninstalling and Re-installing won't help. It says DLL load failed
as window file is not found. The next time I import it says pandas
don't have core attribute, ut core folder is present in the directory.
I am using Python 3.6 and Windows 10. How to remove this error?
-- 
Bhavna Soni
Electronics and Telecommunications
National Institute of Technology, Raipur
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem importing pandas library

2018-05-27 Thread Alan Gauld via Tutor
On 27/05/18 04:43, Bhavna Soni wrote:
> I installed pandas library using pip9. I get errors while importing
> it, Uninstalling and Re-installing won't help. It says DLL load failed
> as window file is not found. The next time I import it says pandas
> don't have core attribute, ut core folder is present in the directory.
> I am using Python 3.6 and Windows 10. How to remove this error?
> 

It may be a hammer to a nut solution but it may be simpler to just
install an all-in-one distibution like Anaconda. It may be a step
behind leading edge but most folks don;t need leading edge and
it avoids all the hassles of sorting out dependencies etc.

https://www.anaconda.com/download

Especially since your sig suggests you might want to use more
than just pandas from the SciPy/Scikit package collection.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem importing pandas library

2018-05-27 Thread Mats Wichmann
On 05/27/2018 01:18 AM, Alan Gauld via Tutor wrote:
> On 27/05/18 04:43, Bhavna Soni wrote:
>> I installed pandas library using pip9. I get errors while importing
>> it, Uninstalling and Re-installing won't help. It says DLL load failed
>> as window file is not found. The next time I import it says pandas
>> don't have core attribute, ut core folder is present in the directory.
>> I am using Python 3.6 and Windows 10. How to remove this error?
>>
> 
> It may be a hammer to a nut solution but it may be simpler to just
> install an all-in-one distibution like Anaconda. It may be a step
> behind leading edge but most folks don;t need leading edge and
> it avoids all the hassles of sorting out dependencies etc.
> 
> https://www.anaconda.com/download
> 
> Especially since your sig suggests you might want to use more
> than just pandas from the SciPy/Scikit package collection.
> 

Second the suggestion since Anaconda exists pretty much to make it
easier for folks to work with this exact scenario.  For some reason,
installs of these have proven notoriously hard to get right on Windows.
The lighter weight Miniconda may also suit your purposes, this page has
some tips to help you choose if you choose to go this route:

https://conda.io/docs/user-guide/install/download.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Tkinter widget (label) updated by TCP/IP message

2018-05-27 Thread Alejandro Chirife via Tutor

Hi all, I am having a hard time to create what at first looked like a simple 
program with Python 3 and Tkinter:
The UI consist of a window with a label and a button.  
The label shows "waiting for a message" and the button shows "reset display".  
The handler for the button click just resets the label text to "waiting for a 
message".    
The program would draw the window with the two widgets with root.mainloop() 
while it is capable of listening  on a TCP port for an arriving message like 
"hello world", and when it arrives it would show the text in the label.    
The received message should show in the label until any of the following occurs:

- Has been shown for 10 seconds- Another packet arrived with new message (will 
show the new message in the label)- User clicks on the "reset display" button
I will really appreciate if someone could give me some guidance on how to 
manage this with Python 3.

Thanks!AC
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Storing passwords and version control

2018-05-27 Thread Pat Martin
Hello all,

I am writing a script that will be using an API to connect to some systems
to pull info for a search. Since it will be a script I will be running
through cron I won't be able to type the password at time of running. I
also am going to be putting this in source control, using git specifically.

The process I am currently thinking of using is having a separate file with
the username and password in it and just having that ignored by source
control. That of course doesn't solve the problem of the password sitting
in a file on the system unencrypted. Is there a better or more accepted way
to do this in python?

Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Storing passwords and version control

2018-05-27 Thread Joel Goldstick
On Sun, May 27, 2018 at 12:08 PM, Pat Martin  wrote:
> Hello all,
>
> I am writing a script that will be using an API to connect to some systems
> to pull info for a search. Since it will be a script I will be running
> through cron I won't be able to type the password at time of running. I
> also am going to be putting this in source control, using git specifically.
>
> The process I am currently thinking of using is having a separate file with
> the username and password in it and just having that ignored by source
> control. That of course doesn't solve the problem of the password sitting
> in a file on the system unencrypted. Is there a better or more accepted way
> to do this in python?
>
> Thanks
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


You can set environment variables on the system that runs the script.
Then the script reads the environment variables.  This keeps the
secrets out of code anywhere.

On your local machine you can ssh into the target machine and set the
environment as required
-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter widget (label) updated by TCP/IP message

2018-05-27 Thread Alan Gauld via Tutor
On 27/05/18 16:18, Alejandro Chirife via Tutor wrote:
> 
> Hi all, I am having a hard time to create what at first looked like a simple 
> program with Python 3 and Tkinter:
> The UI consist of a window with a label and a button.  
> The label shows "waiting for a message" and the button shows "reset display". 
>  
> The handler for the button click just resets the label text to "waiting for a 
> message".    

So far so good, it is all standard Tkinter programming but

> The program would draw the window with the two widgets with root.mainloop()> 
> while it is capable of listening  on a TCP port for an arriving message

This is not so good. You can't do anything in your code after you call
mainloop(). Thats just the nature of event driven programming. Once
mainloop() is called all control rests with the GUI and you can only
respond to events. Sooo

> like "hello world", and when it arrives it would show the text in the label.  
>   

You need to put your network listener in a separate thread started
before you call mainloop(). Then when a message is received you need to
generate an event in your Tkinter GUI (or you could just call an event
handler directly but that's considered bad practice (for some good
reasons!).

> The received message should show in the label until any of the following 
> occurs:
> 
> - Has been shown for 10 seconds

Set a timer in the GUI that expires after 10 seconds

- Another packet arrived with new message (will show the new message in
the label)

Generate (or call) the same event as before but don't
forget to cancel the current timer.

- User clicks on the "reset display" button

In the button event handler
- Cancel the timer.
- Display whatever the reset message says

So in pseudo code you need:

import tkinter as tk

def button_click()
cancel timer
display default message

def display_message(msg):
display msg on label
cancel current timer
create new 10s timer

def timeout():
display ???

def get_network_message()
your network receiving code here

if is_valid_message(msg):
   display_message(msg)

def main():
create GUI
bind events
create thread to run get_network_message
mainloop()


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Storing passwords and version control

2018-05-27 Thread Alan Gauld via Tutor
On 27/05/18 17:21, Joel Goldstick wrote:
> On Sun, May 27, 2018 at 12:08 PM, Pat Martin  wrote:
>> ... Since it will be a script I will be running
>> through cron I won't be able to type the password 

> You can set environment variables on the system that runs the script.

EV was my initial thought but...Would that work for a cron job?
I didn't think cron picked up the user environment?
Or have I got that wrong? Very possible, since I rarely use cron...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Storing passwords and version control

2018-05-27 Thread Mats Wichmann
On 05/27/2018 11:08 AM, Alan Gauld via Tutor wrote:
> On 27/05/18 17:21, Joel Goldstick wrote:
>> On Sun, May 27, 2018 at 12:08 PM, Pat Martin  wrote:
>>> ... Since it will be a script I will be running
>>> through cron I won't be able to type the password 
> 
>> You can set environment variables on the system that runs the script.
> 
> EV was my initial thought but...Would that work for a cron job?
> I didn't think cron picked up the user environment?
> Or have I got that wrong? Very possible, since I rarely use cron...
> 

It doesn't pick up your login environment, but it can still be given
EVs. However that's not (much) more safe: the way a process was called
can be examined, so you can fish the passwords out while it is active.

More classical schemes for this involve using a third party to make
things work: read up on using a token, OAuth style;  or if the
environment is more local and you're really only looking for a login
password, a password agent like ssh uses.




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Storing passwords and version control

2018-05-27 Thread Danny Yoo
The recommendations in
https://stackoverflow.com/questions/7014953/i-need-to-securely-store-a-username-and-password-in-python-what-are-my-options
might apply.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] get key value from Redis instance

2018-05-27 Thread Silviu Chiric
Dear all

I need to get the value of given key from Redis, or both key and value, the
below code snippet fails always, even the connection is okay

StrictRedis>>
Connected!

My code
import redis

try:
conn = redis.StrictRedis( host='
redis-15838.c44.us-east-1-2.ec2.cloud.redislabs.com', port=15838,
password='DavidLavinia2')
print (conn)
conn.ping()
print ('Connected!')
print 'Set Record:', conn.set("best_car_ever", "Tesla Model S")
print 'Get Record:', conn.get("best_car_ever")
print 'Delete Record:', conn.delete("best_car_ever")
print 'Get Deleted Record:', conn.get("best_car_ever")
except Exception as ex:
print ('Error:', ex)
exit('Failed to connect, terminating.')

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] get key value from Redis instance

2018-05-27 Thread Danny Yoo
On Sun, May 27, 2018 at 3:02 PM Silviu Chiric 
wrote:

> Dear all

> I need to get the value of given key from Redis, or both key and value,
the
> below code snippet fails always, even the connection is okay

What is the error you see?  Please also include the error message, verbatim.

Computer systems are complex.  You've made an assumption that something in
your program is causing the error that you're seeing.  But there might be
some other cause.  In order to help the volunteers here to accurately
diagnose problems, you should try to also include error message output in
your report.

Also, it is normally a bad idea to include password information in a
program's source code.  I would *strongly* suggest you change your password
to your Redis database if it's a real password, as you've just
inadvertently shared it with the rest of the open Internet.

 From a first glance: it looks like one of your print statements is not
vertically aligned with the rest of your print statements, so I would
expect Python to be reporting a SyntaxError because of this misalignment.

I would also recommend not to combine mutation statements with print
statements.  That is, rather than:

##
print 'Set Record:', conn.set("best_car_ever", "Tesla Model S")
##

do this instead:

##
set_result = conn.set("best_car_ever", "Tesla Model S")
print 'Set Record:', set_result
##


Likewise, I'd recommend separating out:

##
print 'Delete Record:', conn.delete("best_car_ever")
##

into:

##
delete_result = conn.delete("best_car_ever")
print 'Delete Record', delete_result
##

These changes are intended to help with the readability of the program,
because the important statements that modify the database will stand out.
Compare with the previous, where because those modification statements are
nested within the 'print' statement, they are easier to overlook.


Hope that makes sense.  Good luck to you!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] get key value from Redis instance

2018-05-27 Thread Danny Yoo
>   From a first glance: it looks like one of your print statements is not
> vertically aligned with the rest of your print statements, so I would
> expect Python to be reporting a SyntaxError because of this misalignment.

Substitute the word "vertical" with "horizontal".   Sorry: I made yet
another mental typo there.  :P
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] get key value from Redis instance

2018-05-27 Thread Danny Yoo
One other recommendation: remove the try/except block for now.  Don't use
exception handling.

We want to use exception handling if we have any significant recovery
logic, or if it's important not to expose program errors to the end user.
But your situation doesn't match this.  In fact, you want to see errors as
they happen, and as close to their root cause as possible.  Exception
handling, in that case, is harmful: it allows the programmer to
accidentally make their debugging job *harder*.


Hope this helps!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] get key value from Redis instance

2018-05-27 Thread Alan Gauld via Tutor
On 27/05/18 19:31, Silviu Chiric wrote:
> Dear all
> 
> I need to get the value of given key from Redis, or both key and value, the
> below code snippet fails always, even the connection is okay

Please post the output. You print the error trace but we cant see it.

Or if that is the the whole output please remove the try/except clause
since it may be hiding valuable error information.

> import redis
> 
> try:
> conn = redis.StrictRedis( host='
> redis-15838.c44.us-east-1-2.ec2.cloud.redislabs.com', port=15838,
> password='DavidLavinia2')
> print (conn)
> conn.ping()
> print ('Connected!')
> print 'Set Record:', conn.set("best_car_ever", "Tesla Model S")

This appears to break indentation, but I'd expect an error
so I assume its an email issue.

If not, fix this first!


> print 'Get Record:', conn.get("best_car_ever")
> print 'Delete Record:', conn.delete("best_car_ever")
> print 'Get Deleted Record:', conn.get("best_car_ever")
> except Exception as ex:
> print ('Error:', ex)
> exit('Failed to connect, terminating.')


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] get key value from Redis instance

2018-05-27 Thread Steven D'Aprano
On Sun, May 27, 2018 at 08:31:26PM +0200, Silviu Chiric wrote:

> try:
> conn = redis.StrictRedis( host='
> redis-15838.c44.us-east-1-2.ec2.cloud.redislabs.com', port=15838,
> password='DavidLavinia2')

You just shared your password with the entire world.


> print (conn)
> conn.ping()
> print ('Connected!')
> print 'Set Record:', conn.set("best_car_ever", "Tesla Model S")
> print 'Get Record:', conn.get("best_car_ever")
> print 'Delete Record:', conn.delete("best_car_ever")
> print 'Get Deleted Record:', conn.get("best_car_ever")
> except Exception as ex:
> print ('Error:', ex)
> exit('Failed to connect, terminating.')


Get rid of the try...except block. It is evil.

If a problem occurs, it could happen in any one of twelve operations. 
Six of them are calls to print, so they are probably okay, but the other 
six are complex operations that could go wrong for a billion different 
reasons.

Nevertheless, whatever the *real* reason the code fails, your 
try...except block catches the exception, strips out the useful 
traceback which is indispensible for debugging, and prints a LIE that 
you failed to connect. You didn't fail to connect, as you can see: the 
connection was successfully made.

Don't let your code lie to you. Debugging is hard. When your program 
deliberately strips away the useful traceback information showing which 
line failed, and then lies about the error that occurred, it becomes 
nearly impossible.

(1) Change your password. Immediately.

(2) Remove the try...except block.

(3) When an error occurs, the interpreter will print a full traceback 
showing which line failed as well as the failure type and error message, 
and then exit. There is no need for you to catch the exception and then 
exit yourself.

(4) COPY AND PASTE (don't summarise it, don't retype it from memory) the 
ENTIRE traceback and post it for us to see.


We can't debug a problem we can't see.



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Storing passwords and version control

2018-05-27 Thread Steven D'Aprano
On Sun, May 27, 2018 at 09:08:29AM -0700, Pat Martin wrote:

> The process I am currently thinking of using is having a separate file with
> the username and password in it and just having that ignored by source
> control. That of course doesn't solve the problem of the password sitting
> in a file on the system unencrypted. Is there a better or more accepted way
> to do this in python?

The usual way is to use the netrc module.

https://docs.python.org/3/library/netrc.html


-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor