Re: [Tutor] Python help

2017-07-23 Thread Cameron Simpson

On 23Jul2017 13:40, Winonah Ojanen  wrote:

I also tried the correct command for the mac ox s in terminal shell,
running:

Jims-MacBook-Pro-2:~ Jim$
PYTHONPATH="/Users/Jim/Documents/illustris_python:$PYTHONPATH

export PYTHONPATH

[...]

I did use the pip command and am attempting to add the files to my python
path. I used
 import sys
sys.path.append("/Users/Jim/Documents/illustris_python")


Please always reply-all or reply-to-list.

The python path is a list of places to look for modules. By adding 
'../illustris_python' you're implying you want the module to be at 
'../illustris_python/illustris_python'.


See if using '/Users/Jim/Documents' finds the module. Then move it to a better 
(more targeted) directory and use that directory's name :-)


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


Re: [Tutor] Quick Pythonic Style Tips

2017-07-23 Thread Cameron Simpson

On 23Jul2017 19:02, Abdur-Rahmaan Janhangeer  wrote:

ah pylint yes, great checker ! *some guys thought of inventing it*


Yes, very handy. Greate for checking for simple logic errors too (variable used 
but never bound, missing imports, etc).


Just for folks' interest, I have a shell script called "lint" which I use which 
encapsulates my personal lint practices. Great for a final check before 
committing code.  I append it for anyone else to use or adapt.


Interactively I've got a personal shell function called "lint" which, if no 
files are specificly named, runs that script against whatever files are 
currently modified in my working code repo.  So one can just say "lint" at the 
shell prompt to get a report on one's work in progress.


Script appended below.

Cheers,
Cameron Simpson 

#!/bin/sh
#
# Lint the named files.
#   - Cameron Simpson  22apr2017
#

set -ue

trace=
[ -t 2 ] && trace=set-x

cmd=$0
usage="Usage: $cmd filenames..."

[ $# -gt 0 ] || { echo "$cmd: missing filenames" >&2; echo "$usage" >&2; exit 
2; }

xit=0

for lintfile
do
 case "$lintfile" in
   *.json)
 $trace json-pprint <"$lintfile" 2>&1 >/dev/null || xit=1
 ;;
   *.go)
 $trace go tool vet -all -shadowstrict "$lintfile" || xit=1
 ;;
   *.php)
 { $trace php -l "$lintfile" \
   && $trace phpcs --standard=PSR2 --report=emacs "$lintfile"
 } || xit=1
 ;;
   *.py)
 { $trace python3 -m py_compile "$lintfile" \
   && $trace pyflakes-2.7 "$lintfile" \
   && $trace pep8 
--ignore=E111,E114,E126,E201,E202,E265,E266,E301,E302,E501,E731,W503 "$lintfile" \
   && $trace pylint "$lintfile"
 } || xit=1
 ;;
   *)echo "$cmd: no lint for $lintfile"
 ;;
 esac
done

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


Re: [Tutor] Quick Pythonic Style Tips

2017-07-23 Thread Steven D'Aprano
On Sun, Jul 23, 2017 at 07:02:09PM +0400, Abdur-Rahmaan Janhangeer wrote:

> assert(... is liked by some strongly typed programmers

Not just strongly-typed programmers:

http://import-that.dreamwidth.org/676.html


> data encapsulation might be depressing to some migrating coders

"Data encapsulation" does not mean "data hiding". Python has excellent 
data encapsulation:

- packages encapsulate modules together;

- modules encapsulate classes, functions and variables together;

- classes encapsulate object state and behaviour together.


Compared to languages like C++ and Java, Python's data HIDING is weak. 
Python has no private, public, protected, etc.

But even in the strictest languages like C++ and Java, there is usually 
some way to "defeat" the compiler and get access to private data and 
break data hiding. For instance, in C++ you can often do something like

#define private public

and in Java you can use reflection. The creator of Python, Guido van 
Rossum, understands that sometimes there *are* good uses for breaking 
data hiding (usually for testing and debugging). Because Python is an 
interpreter where most features are done at runtime rather than compile 
time, implementing data hiding in Python would hurt performance, and 
there would be some way to break it anyway.

So why bother?

Instead, Python is "for consenting adults". Data hiding is very simple: 
the developer flags objects they want to keep private with a leading 
underscore:

_private

and that tells you that this is private and you shouldn't touch it. If 
you decide to ignore this and touch it anyway, then:

- either you have a good reason, and that's okay;

- or you are a "consenting adult", and if your code blows up, 
  well, that's your own fault and don't complain to us.



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


Re: [Tutor] Python3 Help

2017-07-23 Thread Alan Gauld via Tutor
On 24/07/17 00:19, Brandon Anderson wrote:

> 2.  I’m trying to locate the directory path to where Python3 is located on my 
> system, but when I enter 
>   the following command:
>   $ type -a python3

You could also try

$ which python3

>   -bash: $: command not found  

The $ is the OS prompt you are not supposed to type it in.

> 3.  How do I determine why I’m getting the ‘error’ command, instead of the 
> directory location of Python3.

The error means that there a mistake in your input.
In this case you included the $ in your input.

Note that this is an OS error and nothing to do
with python itself.

-- 
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] class newbie

2017-07-23 Thread Michael C
thanks!

On Sun, Jul 23, 2017 at 5:35 PM, Danny Yoo  wrote:

> On Sun, Jul 23, 2017 at 1:24 PM, Michael C
>  wrote:
> > class mahschool:
> > def print():
> > print('Say something')
>
>
> By the way, you've chosen a name for your method that's spelled the
> same as the name of the built-in "print" function.  I'd recommend you
> choose a different name than "print" in your method name, just to
> avoid any potential confusion.  This isn't going to solve the
> immediate problem that you encountered and solved: you figured out
> that methods need to have a self argument.  But you probably still
> want to rename to avoid the name collision.
>
>
> Good luck!
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Import Error.

2017-07-23 Thread Steven D'Aprano
On Sun, Jul 23, 2017 at 09:54:09PM +0530, Deepen Patel wrote:

> ImportError: No module named cryptography.exceptions
> 
> Currently, I am using virtual environments and in virtual environment this
> code not run properly.
> previously, I am running code without virtual environments. it works proper.

You need to install the cryptography package into your virtual 
environment. The virtual environment will not see packages installed 
elsewhere.


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


Re: [Tutor] Python3 Help

2017-07-23 Thread Danny Yoo
> 2.  I’m trying to locate the directory path to where Python3 is located on my 
> system, but when I enter
> the following command:
> $ type -a python3
>
> I get:
> -bash: $: command not found


Ah.  Do not include the leading "$" in the command that you're typing.
I'm assuming that you're reading some instruction that says something
like this:

---

Type the following into your command prompt:

$ type -a python3



If you are reading such an instruction, don't literally type the
dollar sign.  "$" is a convention that's used to indicate to you to
type the rest of the line into your command prompt.  It's because, by
default, the command shell will use "$" as its primary prompt to tell
the user that it is ready to accept a new command.
(https://superuser.com/questions/57575/what-is-the-origin-of-the-unix-dollar-prompt)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class newbie

2017-07-23 Thread Mats Wichmann
On 07/23/2017 02:42 PM, Michael C wrote:
> never mind, I forgot to put 'self' in the method definition!

class mahschool:
def print(self):
print('Say something')


a = mahschool()

a.print()

Indeed.  The error message was clear on this - but not in a way that's
always instructive until you're used to it :)

"TypeError: print() takes 0 positional arguments but 1 was given"

A method is called "silently" (you didn't pass it yourself as an
argument when you called print()) with the instance, so you need to
declare such a parameter in the method definition.

And to give myself an excuse for preaching: it's usually not a great
idea to reuse the name of a built-in function.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class newbie

2017-07-23 Thread Danny Yoo
On Sun, Jul 23, 2017 at 1:24 PM, Michael C
 wrote:
> class mahschool:
> def print():
> print('Say something')


By the way, you've chosen a name for your method that's spelled the
same as the name of the built-in "print" function.  I'd recommend you
choose a different name than "print" in your method name, just to
avoid any potential confusion.  This isn't going to solve the
immediate problem that you encountered and solved: you figured out
that methods need to have a self argument.  But you probably still
want to rename to avoid the name collision.


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


Re: [Tutor] class newbie

2017-07-23 Thread Michael C
never mind, I forgot to put 'self' in the method definition!

class mahschool:
def print(self):
print('Say something')


a = mahschool()

a.print()


On Sun, Jul 23, 2017 at 1:24 PM, Michael C 
wrote:

> class mahschool:
> def print():
> print('Say something')
>
>
> a = mahschool()
>
> a.print()
>
>
>
> With this, I get this error:
>
> Traceback (most recent call last):
>   File "test.py", line 8, in 
> a.print()
> TypeError: print() takes 0 positional arguments but 1 was given
>
>
> What did I do wrong?
>
> Thanks!
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] class newbie

2017-07-23 Thread Michael C
class mahschool:
def print():
print('Say something')


a = mahschool()

a.print()



With this, I get this error:

Traceback (most recent call last):
  File "test.py", line 8, in 
a.print()
TypeError: print() takes 0 positional arguments but 1 was given


What did I do wrong?

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


[Tutor] Python3 Help

2017-07-23 Thread Brandon Anderson
Hello!

1.  I have Python3 installed on my 2017 MacBook Pro. I know that it is 
successfully installed because, when I enter “Python3’ into my terminal,
I get the following message:

Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

2.  I’m trying to locate the directory path to where Python3 is located on my 
system, but when I enter 
the following command:
$ type -a python3

I get:
-bash: $: command not found  

My understanding is that the command should have provided me with the 
path to Python3 is located on my system.

3.  How do I determine why I’m getting the ‘error’ command, instead of the 
directory location of Python3.
I need the location in order to setup my Text Editor to execute Python3 
commands.

Thank you in advance.

Brandon Anderson
(510) 468-0154
brandonander...@icloud.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: Re: Python Help

2017-07-23 Thread Alan Gauld via Tutor
Forwarding to list



 Forwarded Message 

I did use the pip command and am attempting to add the files to my
python path. I used
 import sys
sys.path.append("/Users/Jim/Documents/illustris_python")

and that worked. I even checked to make sure the files were there 


import sys
print (sys.path)

['', '/Users/Jim/anaconda/lib/python36.zip',
'/Users/Jim/anaconda/lib/python3.6',
'/Users/Jim/anaconda/lib/python3.6/lib-dynload',
'/Users/Jim/anaconda/lib/python3.6/site-packages',
'/Users/Jim/anaconda/lib/python3.6/site-packages/Sphinx-1.5.6-py3.6.egg',
'/Users/Jim/anaconda/lib/python3.6/site-packages/aeosa',
'/Users/Jim/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg',
'/Users/Jim/anaconda/lib/python3.6/site-packages/IPython/extensions',
'/Users/Jim/.ipython', 'Users/Jim/Documents/illustris_python']

the file is clearly there but when i try to do import illustris_python
as il it still can't find the module. 

I also figured that I need to manually export to python path so i tried:
export PYTHONPATH=$PYTHONPATH:/Users/Jim/Documents/illustris_python/
  File "", line 1
export PYTHONPATH=$PYTHONPATH:/Users/Jim/Documents/illustris_python/
^
SyntaxError: invalid syntax

I got invalid syntax... using a mac os x

I tried typing in terminal open .bash_profile and telling it to export
the python path in there like some others recommended but in terminal it
is giving me an error message for that... it must not be the right
command for the shell.

Winonah

On Sat, Jul 22, 2017 at 9:34 PM, Cameron Simpson > wrote:

On 23Jul2017 00:20, Alan Gauld > wrote:

On 22/07/17 19:14, Winonah Ojanen wrote:

using python with anaconda in jupiter notebook. However, I
am having


Usual caveat: The tutor list is targeted at the standard library
so any help for non standard library modules is best sought from
the library support fora. In this case that includes the SciPy forum
and any illustris one.


Though arguably the OP's problem is an import issue, not really
module specific.

That having been said, I'll take a guess...

$ mkdir Illustris-3
$ mkdir Illustris-3/groups_135

Are these folders in your PYTHONPATH? If not Python will not
find them.

import illustris_python as il

---
ModuleNotFoundError   Traceback (most
recent call last)


The OP cded into the new dir; I'd normally expect things to be found
if the module was a local file/dir. However...

For some reason the computer is not recognizing this as a
file on my
computer. The CCA folks says this is a coding problem and
not an illustris
problem. any ideas to get me past this? I may also need help
getting
farther into the download process.


I just ran the OP's download command:

 wget -nd -nc -nv -e robots=off -l 1 -r -A hdf5
--content-disposition --header="API-Key:
d522db2e1b33e36d3b365cc9ac1c2c5d"

"http://www.illustris-project.org/api/Illustris-3/files/groupcat-135/?format=api

"

This doesn't seem to download any Python code at all. It does get a
couple of HDF files, presumably with data to work with.

So the issue is initially that the module isn't present anywhere.
Looking at the instructions cited
>, they only
cover fetching som data and working; they presume the software is
already present. I don't immediately see actual software
installation instructions, and it is not presented in PyPI.

Most like the OP will have to install the software directly from:

 https://bitbucket.org/illustris/illustris_python


This command:

 hg clone
https://bitbucket.org/illustris/stris_pythonillustris_python


should produce an "illustris_python" in the current directory, and
then her import command will find it.

However, there are other prerequisites. This pip command:

 pip install h5py numpy

seems to resolve them. The OP will need to use Python 2 because the
module seems to rely on a relative import (for its "util.py" file).

Cheers,
Cameron Simpson >

___
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options:

[Tutor] Fwd: Re: Python Help

2017-07-23 Thread Alan Gauld via Tutor

Forwarding to list,
please use ReplyAll or ReplyList when responding to the list.


 Forwarded Message 

I also tried the correct command for the mac ox s in terminal shell,
running:

Jims-MacBook-Pro-2:~ Jim$
PYTHONPATH="/Users/Jim/Documents/illustris_python:$PYTHONPATH

> export PYTHONPATH


no error messages there but it is still not finding the module through
python.

Winonah


On Sun, Jul 23, 2017 at 1:34 PM, Winonah Ojanen > wrote:

I did use the pip command and am attempting to add the files to my
python path. I used
 import sys
sys.path.append("/Users/Jim/Documents/illustris_python")

and that worked. I even checked to make sure the files were there 


import sys
print (sys.path)

['', '/Users/Jim/anaconda/lib/python36.zip',
'/Users/Jim/anaconda/lib/python3.6',
'/Users/Jim/anaconda/lib/python3.6/lib-dynload',
'/Users/Jim/anaconda/lib/python3.6/site-packages',
'/Users/Jim/anaconda/lib/python3.6/site-packages/Sphinx-1.5.6-py3.6.egg',
'/Users/Jim/anaconda/lib/python3.6/site-packages/aeosa',

'/Users/Jim/anaconda/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg',
'/Users/Jim/anaconda/lib/python3.6/site-packages/IPython/extensions',
'/Users/Jim/.ipython', 'Users/Jim/Documents/illustris_python']

the file is clearly there but when i try to do import
illustris_python as il it still can't find the module.


Note that only shows the folder is in the path.

What does an 'ls' listing reveal as to the contents of the folder?
Is there a file called illustris_python.py? or maybe illustris_python.pyc?



I also figured that I need to manually export to python path so i tried:
export PYTHONPATH=$PYTHONPATH:/Users/Jim/Documents/illustris_python/
  File "", line 1
export PYTHONPATH=$PYTHONPATH:/Users/Jim/Documents/illustris_python/
^
SyntaxError: invalid syntax

I got invalid syntax... using a mac os x

I tried typing in terminal open .bash_profile and telling it to
export the python path in there like some others recommended but in
terminal it is giving me an error message for that... it must not be
the right command for the shell.

Winonah

On Sat, Jul 22, 2017 at 9:34 PM, Cameron Simpson > wrote:

On 23Jul2017 00:20, Alan Gauld > wrote:

On 22/07/17 19:14, Winonah Ojanen wrote:

using python with anaconda in jupiter notebook. However,
I am having


Usual caveat: The tutor list is targeted at the standard library
so any help for non standard library modules is best sought from
the library support fora. In this case that includes the
SciPy forum
and any illustris one.


Though arguably the OP's problem is an import issue, not really
module specific.

That having been said, I'll take a guess...

$ mkdir Illustris-3
$ mkdir Illustris-3/groups_135

Are these folders in your PYTHONPATH? If not Python will not
find them.

import illustris_python as il

---
ModuleNotFoundError   Traceback
(most recent call last)


The OP cded into the new dir; I'd normally expect things to be
found if the module was a local file/dir. However...

For some reason the computer is not recognizing this as
a file on my
computer. The CCA folks says this is a coding problem
and not an illustris
problem. any ideas to get me past this? I may also need
help getting
farther into the download process.


I just ran the OP's download command:

 wget -nd -nc -nv -e robots=off -l 1 -r -A hdf5
--content-disposition --header="API-Key:
d522db2e1b33e36d3b365cc9ac1c2c5d"

"http://www.illustris-project.org/api/Illustris-3/files/groupcat-135/?format=api

"

This doesn't seem to download any Python code at all. It does
get a couple of HDF files, presumably with data to work with.

So the issue is initially that the module isn't present
anywhere. Looking at the instructions cited
>, they
only cover fetching som data and working; they presume the
software is already present. I don't immediately see actual
software installation instructions, and it is not presented 

Re: [Tutor] [Cryptography-dev] Import Error.

2017-07-23 Thread Alex Gaynor
Hi Deepen,

Without any more information, it looks like you didn't install cryptography
into your virtualenv. How did you install twisted?

Alex

On Sun, Jul 23, 2017 at 12:24 PM, Deepen Patel  wrote:

> Hi,
>
> I got error like Import error.
>
> Traceback (most recent call last):
>   File "startnode.py", line 8, in 
> from twisted.conch import manhole, manhole_ssh
>   File "/usr/local/lib/python2.7/dist-packages/twisted/conch/manhole_ssh.py",
> line 14, in 
> from twisted.conch.ssh import factory, session
>   File "/usr/local/lib/python2.7/dist-packages/twisted/conch/ssh/factory.py",
> line 18, in 
> from twisted.conch.ssh import (_kex, transport, userauth, connection)
>   File 
> "/usr/local/lib/python2.7/dist-packages/twisted/conch/ssh/transport.py",
> line 22, in 
> from cryptography.exceptions import UnsupportedAlgorithm
> ImportError: No module named cryptography.exceptions
>
> Currently, I am using virtual environments and in virtual environment this
> code not run properly.
> previously, I am running code without virtual environments. it works
> proper.
>
> Await your reply.
>
> Regards,
> Deepen Patel.
>
> ___
> Cryptography-dev mailing list
> cryptography-...@python.org
> https://mail.python.org/mailman/listinfo/cryptography-dev
>
>


-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: D1B3 ADC0 E023 8CA6
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quick Pythonic Style Tips

2017-07-23 Thread Abdur-Rahmaan Janhangeer
Thanks everybody, i wanted to get some pythonic ideas.

yes forgot that

assert(... is liked by some strongly typed programmers

anInt -> did not not some people liked tha

data encapsulation might be depressing to some migrating coders

ah pylint yes, great checker ! *some guys thought of inventing it*

Else more styling tips if any and whenever, appreciated !

Abdur-Rahmaan Janhangeer,
Mauritius
abdurrahmaanjanhangeer.wordpress.com

On 23 Jul 2017 01:59, "Danny Yoo"  wrote:

> > I'd like to contibute a rather different sort of tidbit to what Alan
> > wrote: be really careful about using mutable data types in function
> > calls, as class variables, and just in general.
>
> By the way, there are some tools known as "linters" that can help
> catch these kind of errors.  https://www.pylint.org/ is one of them,
> and it is worth using.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Best OpenCV tutorials

2017-07-23 Thread Abdur-Rahmaan Janhangeer
The last python issue i'd like to resolve is the OpenCV issue

I just want some nice opencv tutorials apart from the official docs

also, some nice algos if any apart from Haar Cascades with examples.

P.s. This is a 3rd party lib, so, some links is fine !

Abdur-Rahmaan Janhangeer,
Mauritius
abdurrahmaanjanhangeer.wordpress.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Import Error.

2017-07-23 Thread Deepen Patel
Hi,

I got error like Import error.

Traceback (most recent call last):
  File "startnode.py", line 8, in 
from twisted.conch import manhole, manhole_ssh
  File
"/usr/local/lib/python2.7/dist-packages/twisted/conch/manhole_ssh.py", line
14, in 
from twisted.conch.ssh import factory, session
  File
"/usr/local/lib/python2.7/dist-packages/twisted/conch/ssh/factory.py", line
18, in 
from twisted.conch.ssh import (_kex, transport, userauth, connection)
  File
"/usr/local/lib/python2.7/dist-packages/twisted/conch/ssh/transport.py",
line 22, in 
from cryptography.exceptions import UnsupportedAlgorithm
ImportError: No module named cryptography.exceptions

Currently, I am using virtual environments and in virtual environment this
code not run properly.
previously, I am running code without virtual environments. it works proper.

Await your reply.

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


Re: [Tutor] Import Error.

2017-07-23 Thread Peter Otten
Deepen Patel wrote:

> Hi,
> 
> I got error like Import error.
> 
> Traceback (most recent call last):
>   File "startnode.py", line 8, in 
> from twisted.conch import manhole, manhole_ssh
>   File
> "/usr/local/lib/python2.7/dist-packages/twisted/conch/manhole_ssh.py",
> line 14, in 
> from twisted.conch.ssh import factory, session
>   File
> "/usr/local/lib/python2.7/dist-packages/twisted/conch/ssh/factory.py",
> line 18, in 
> from twisted.conch.ssh import (_kex, transport, userauth, connection)
>   File
> "/usr/local/lib/python2.7/dist-packages/twisted/conch/ssh/transport.py",
> line 22, in 
> from cryptography.exceptions import UnsupportedAlgorithm
> ImportError: No module named cryptography.exceptions
> 
> Currently, I am using virtual environments and in virtual environment this
> code not run properly.
> previously, I am running code without virtual environments. it works
> proper.
> 
> Await your reply.
> 
> Regards,
> Deepen Patel.

If I understand

https://github.com/twisted/twisted/blob/trunk/INSTALL.rst

and

http://twistedmatrix.com/documents/current/installation/howto/optional.html

correctly you have to install with

$ pip install twisted[conch]

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


Re: [Tutor] new to python

2017-07-23 Thread Mats Wichmann
On 07/23/2017 09:16 AM, Alex Kleider wrote:
> On 2017-07-23 01:06, Anish Tambe wrote:
>>> for line in file:
>>
>> This line is not required as the you have opened your file to 'f'.
>> 'file' is a built-in class. Type -
>> help(file)
>> on the interpreter to know more about it.
> 
> This appears to be true in python2x but not in python3:
> 
> alex@X301n3:~$ python3
> Python 3.4.3 (default, Nov 17 2016, 01:11:57)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 help(file)
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'file' is not defined
 exit()
> alex@X301n3:~$ python
> Python 2.7.6 (default, Oct 26 2016, 20:32:47)
> [GCC 4.8.4] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 help(file)
> Help on class file in module __builtin__:
> 
> class file(object)
>  |  file(name[, mode[, buffering]]) -> file object
>  |
> ...

It is nonetheless still true that Python provides context manager
support for file objects that behave the same way as described (that is,
when handle - called 'f' in the example above - goes out of scope, it is
closed for you).  Otherwise, the relevant documentation on file objects
is now in the IO discussion:

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

> Also puzzling is that the 'intro' to python2 declares itself to be 'on
> linux2' vs just 'on linux' in the case of python3.  (Something I'd not
> previously noticed.)

That's just a cleanup of an old issue, Python3 dropped the "linux2"
thing (which was never a great idea, linux kernels are now 4.x after 2.x
lived for a very long time, Python never followed those changes nor did
it need to);

FWIW, the preferred method now to check if a host is linux is to do:

if sys.platform.startswith("linux"):

instead of checking explicitly for a string "linux", "linux2", etc.



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


Re: [Tutor] new to python

2017-07-23 Thread Alex Kleider

On 2017-07-23 01:06, Anish Tambe wrote:

for line in file:


This line is not required as the you have opened your file to 'f'.
'file' is a built-in class. Type -
help(file)
on the interpreter to know more about it.


This appears to be true in python2x but not in python3:

alex@X301n3:~$ python3
Python 3.4.3 (default, Nov 17 2016, 01:11:57)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.

help(file)

Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'file' is not defined

exit()

alex@X301n3:~$ python
Python 2.7.6 (default, Oct 26 2016, 20:32:47)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

help(file)

Help on class file in module __builtin__:

class file(object)
 |  file(name[, mode[, buffering]]) -> file object
 |
...

Also puzzling is that the 'intro' to python2 declares itself to be 'on 
linux2' vs just 'on linux' in the case of python3.  (Something I'd not 
previously noticed.)




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


Re: [Tutor] new to python

2017-07-23 Thread Peter Otten
N6Ghost wrote:

> C:\coderoot\python3\level1>python
> Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> 
> /windows 10 x64
> 
> new to python, but not really new to programming.
> 
> going through the beginners docs, I am stuck on the file handling opening:
> 
> 
>my code so far:
> 
> f = open("C:\coderoot\python3\level1\inputfile.txt", 'r')

While this one is OK using backslashes in a normal string will sooner or 
later produce erroneous paths:

>>> print("C:\test")
C:  est

Oops, \t is a TAB char, not a backslash followed by a 't'. Possible 
solutions are 

- always escape the backslash "C:\\test"
- use raw strings r"C:\test"
- use forward slashes for file paths: "C:/test" (yes, it works even on
  windows)

> for line in file:

It looks like file isn't defined anywhere.

>  for line in f:
>  print(line.rstripe())
>  f.close()

It looks like f.close() is indentend one level to deep -- the file will be 
closed on the second iteration of the inner loop. 

Indentation is important as Python uses it to represent the code structure.  
If your editor alows it ensure that it converts one hit of the TAB key into 
four spaces to avoid discrepancies between what you see and what you have.
 
> I want to try the different methods of opening files and reading them.
> and processing the data.  from there I will then start with writing to
> files.
> 
> 
> any idea why that does not work?

Since you can already program:

Read the traceback and error message carefully -- they prodvide valuable 
hints. 

If you cannot make sense of them please provide them along with the code 
that produced them; use cut-and-paste for both code and traceback.

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


Re: [Tutor] new to python

2017-07-23 Thread Anish Tambe
> for line in file:

This line is not required as the you have opened your file to 'f'.
'file' is a built-in class. Type -
help(file)
on the interpreter to know more about it.

> for line in f:
> print(line.rstripe())
> f.close()

Are you sure that you need to close the file after reading each line?

>
> I want to try the different methods of opening files and reading them.
and processing the data.  from there I will then start with writing to
files.

Bonus : read about the 'with' keyword.

> any idea why that does not work?

When you say the code does not work, you should provide the exact error or
stacktrace that you see.

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


Re: [Tutor] new to python

2017-07-23 Thread Alan Gauld via Tutor
On 23/07/17 07:26, N6Ghost wrote:

> 
> f = open("C:\coderoot\python3\level1\inputfile.txt", 'r')
> for line in file:

Note that you have no variable called 'file'.
So this line doesn't make sense.

>  for line in f:
>  print(line.rstripe())

This bit will work if you omit the line above and
fix the indentation. (and remove the 'e' from strip()

>  f.close()

This should be outside the loop, you don't want
to close the file after every line.

Finally, there is another way to do this which
is considered 'better'/more Pythonic:

with open("C:\coderoot\python3\level1\inputfile.txt", 'r') as f:
 for line in f:
 print(line.strip())

Notice with this construct the closing of the file is
handled for you.

> any idea why that does not work?

When posting questions always include the full error text.
Although apparently cryptic it actually contains a lot of
useful detail which saves us from making guesses.


-- 
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


[Tutor] new to python

2017-07-23 Thread N6Ghost

C:\coderoot\python3\level1>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit 
(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

/windows 10 x64

new to python, but not really new to programming.

going through the beginners docs, I am stuck on the file handling opening:


  my code so far:

f = open("C:\coderoot\python3\level1\inputfile.txt", 'r')
for line in file:
for line in f:
print(line.rstripe())
f.close()

I want to try the different methods of opening files and reading them. 
and processing the data.  from there I will then start with writing to 
files.



any idea why that does not work?


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