Re: [Tutor] Need some help with setuptools for my project.

2015-04-07 Thread Anubhav Yadav
You might consider packaging your project as a script so that it can be run
> by the user from the command line. See:
> https://docs.python.org/2/distutils/setupscript.html#installing-scripts
>
> Provided that you add something like #!/usr/bin/python to the top of
> scorer.py, 'python setup.py install’ will make it executable and move it to
> /usr/local/bin (on mac anyway) so that it can be run from the command line
> without the need to be in a specific directory or use the python command.
> You can even drop the .py from the file name so the user would just type in
> ‘scorer’ to start the script.
>
>
Hi, as you can see my project doesn't have any single script. It is now
made of many modules, and the app.py imports all the modules and executes
them in the main() function. I also have an __main__.py where I call the
main() function. I can run my project from the root of the directory using
``python -m scorer``. But if I use setuptools and install python using
``sudo python setup.py install``, setuptools says that my script is
installed but I don't know how to run it?



> If you’d like to make your script available to the wider community, you
> can put it on PyPI. See:
> https://docs.python.org/2/distutils/packageindex.html
>

I would love to upload my script to PyPi, but first I need to figure out if
my project is getting installed properly using setuptools or not.


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


Re: [Tutor] Why is it invalid syntax to have a particular dictionary value as an argument?

2015-04-07 Thread Emile van Sebille

On 4/6/2015 12:42 PM, Dave Angel wrote:

On 04/06/2015 03:20 PM, Emile van Sebille wrote:



Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> d = {'a':'123'}
 >>> def func(s=d['a']):
...   print s
...
 >>> func()
123



Only if you know that nobody is going to be changing d.


Clearly my example avoids the pitfalls of a changing d.  :)


 >>> d = {"a":"123"}
 >>> def func(s=d["a"]):
... print s
...
 >>> d["a"] = "new value"
 >>> func()
123


Good point -- I forgot about setting default parameters at compile time.

>>> d={'a':'123'}
>>> def func(s=d):print s['a']
...
>>> func()
123
>>>
>>> d['a']='456'
>>> func()
456
>>>



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


Re: [Tutor] Need some help with setuptools for my project.

2015-04-07 Thread Anubhav Yadav
>
> On your GitHub repository, you have a single file, scorer.py. I think that
> this is a better approach in this instance than the multiple file approach
> you have now taken (see below).
>

I am sorry I linked the master repository. See the structureCode branch[1].

>
> > setuptools says that my script is installed but I don't know how to run
> it?
>
> setuptools will have installed your module to site-packages so that other
> developers can import it to use in writing their own code. However, your
> code doesn’t provide anything for developers e.g. new functions, classes
> etc. so this isn’t really want you want. Rather, your code should be run by
> the end user, the cricket fan. From the first link I gave:
>
> “Python modules...are usually not run by themselves but imported by
> scripts. Scripts are files containing Python source code, intended to be
> started from the command line"
>
> The latter sounds much more like your situation, so I recommend you do it
> that way. Scripts like this should be single files, hence my recommendation
> to use one file.
>
> Hope that helps,
>

This certainly helps, if you see the new link that I have given this time,
you will notice that I have an app.py in my project dir, and it has the
main() function. I have called the main function in __main__.py. This[2]
blog post tells me that you can run your app using ``python -m scorer``
from the root directory of the project, and indeed I am able to run my
scorer app like this.

Now my question is  how can I use setup tools so that users can just run
"scorer" from the command line and the my script(which was installed before
by setuptools) will start?

[1] https://github.com/neo1691/scorer.py/tree/structureCode
[2] http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/

-- 
Regards,
Anubhav Yadav
KPIT Technologies,
Pune.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need some help with setuptools for my project.

2015-04-07 Thread Anubhav Yadav
I apologise, my method was for distutils, not setuptools. I get the two
> muddled. The mechanism for creating a console script like you describe with
> setuptools is described here[1]. The post you linked also has a section on
> it under the heading ‘Executable scripts’. It allows for the multiple file
> approach you have.
>
> This is it, here's what I did:

I edited my setup.py and added the following:
  entry_points={
'console_scripts':[
'scorer = scorer.app.main'
]
},

As the main function is in scorer/app.py.

Now after running sudo python setup.py install, I can see that there is a
scorer binary installed in my system, but when I run that, I get the
following error.

Traceback (most recent call last):
  File "/usr/bin/scorer", line 9, in 
load_entry_point('scorer==0.1', 'console_scripts', 'scorer')()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line
546, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line
2666, in load_entry_point
return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line
2339, in load
return self.resolve()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line
2345, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named main

I am this close I guess!

As an aside, I would also suggest that you look at PEP8, the Python style
> guide[3]. Your code should really conform to it as much as possible.
>

And thanks a lot for giving me the PEP8 link, it will be helpful.

>
> [1]
> https://pythonhosted.org/setuptools/setuptools.html#automatic-script-creation
> [2] https://www.python.org/dev/peps/pep-0008/
>
>
> —
>
> Dylan Evans
>



-- 
Regards,
Anubhav Yadav
KPIT Technologies,
Pune.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] help

2015-04-07 Thread Francesca Ghidelli
Hello,First of all, i'm not trying to learn how to program with Python. I use 
Blender for my project, Blender 2.49b uses Python262. when i try to export the 
mesh from Blender to an other program, python doesn't work and show the error 
like the screenshot in annex. I've just  installed numpy 1.3.0, but i tried 
different version before , it shows always the same error.I have Windows 
7...could you find a solution for my problem?

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


Re: [Tutor] help

2015-04-07 Thread Alan Gauld

On 07/04/15 21:52, Francesca Ghidelli wrote:

Hello,First of all, i'm not trying to learn how to program with Python.


OK. So how exactly are you using Python?

> I use Blender for my project, Blender 2.49b uses Python262.

This is a list for folks learning Python so we don't necessarily
know much about Blender. as I understand it Python is Blenders
macro language. Is that what you are doing? Running a macro?


 i try to export the mesh from Blender to an other program,


What's a mesh? How does python feature in the export?


python doesn't work and show the error like the screenshot in annex.


This is a mailing list. Many email gateways don't allow attachments.
Your' got lost. Please copy the full error message into your post.
If you can copy the code too - or at least the bit the error refers
to - that would help - remember we don't know much about Blender.


I've just  installed numpy 1.3.0, but i tried different version

> before , it shows always the same error.

Again, not too many here know numpy, it's not part of standard Python. 
How does it fit with Blender and your problem? If the error is a numpy 
error there is a numpy (or sciPy) list that might know more.


There is also a mailing list on gmane.org that is dedicated to Python on 
Blender:


gmane.comp.video.blender.python

You could try asking there. They should at least understand what you
are talking about.

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] Need some help with setuptools for my project.

2015-04-07 Thread Cameron Simpson

On 07Apr2015 21:20, Anubhav Yadav  wrote:

I apologise, my method was for distutils, not setuptools. I get the two

muddled. The mechanism for creating a console script like you describe with
setuptools is described here[1]. The post you linked also has a section on
it under the heading ‘Executable scripts’. It allows for the multiple file
approach you have.

This is it, here's what I did:


I edited my setup.py and added the following:
 entry_points={
   'console_scripts':[
   'scorer = scorer.app.main'
   ]
   },


My megacli module installs its "mcli" script like this:

   'entry_points': {
 'console_scripts': [
 'mcli = cs.app.megacli:main',
 ],

Note the ":" before main, not ".".

Cheers,
Cameron Simpson 

I think... Therefore I ride.  I ride... Therefore I am.
   - Mark Pope 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why is it invalid syntax to have a particular dictionary value as an argument?

2015-04-07 Thread boB Stepp
On Mon, Apr 6, 2015 at 12:54 PM, Dave Angel  wrote:
> On 04/06/2015 12:43 PM, boB Stepp wrote:
>
>>
>> I was breaking down longer functions into smaller ones. Along the way
>> I noticed I was passing an entire dictionary from one function to
>> another. I only needed to pass one particular value, not the whole
>> dictionary, so that is how I got into the issue I asked about.
>
>
> Just to reinforce something you probably know well, passing a dictionary
> takes no more memory or time than passing an item from that dictionary...

One thing about Python that I must keep reminding myself is that its
identifiers store references to objects, not the actual objects
themselves.

> ... The
> real choice is whether the called function should dealing with a single item
> or with a dictionary.  It would have a different name in each case, and a
> different set of reuse possibilities.

In my actual code, I am trying to take advantage of these ideas.

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


Re: [Tutor] Why is it invalid syntax to have a particular dictionary value as an argument?

2015-04-07 Thread boB Stepp
On Mon, Apr 6, 2015 at 2:42 PM, Dave Angel  wrote:
> On 04/06/2015 03:20 PM, Emile van Sebille wrote:
>>
>> On 4/6/2015 7:54 AM, boB Stepp wrote:
>>>

[...]

>>
>> Maybe this form helps:
>>
>> Python 2.7.6 (default, Mar 22 2014, 22:59:56)
>> [GCC 4.8.2] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> d = {'a':'123'}
>>  >>> def func(s=d['a']):
>> ...   print s
>> ...
>>  >>> func()
>> 123
>>
>
> Only if you know that nobody is going to be changing d.
>
 d = {"a":"123"}
 def func(s=d["a"]):
> ... print s
> ...
 d["a"] = "new value"
 func()
> 123

Despite Mark's warning, I feel I must see if I understand what is going on here.

Switching to Py 3.4 since I am now at home:

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600
64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> d = {'a': '123'}
>>> def func(s=d['a']):
  print(s)
  print(d['a'])

>>> func()
123
123
>>> d['a'] = 'new value'
>>> func()
123
new value

I added an additional print to the function to show the dictionary
entry's behavior.

First, my current understanding is that this form of the function does
not object to the presence of d['a'] in its parameter list because s
is the real parameter, d['a'] is its default value, but s is not
actually evaluated until run time.

But once s *is* evaluated, it stores a reference to the original
object, '123'. Changing d['a'] outside the function to a new value
does not alter the fact that s is storing the very same reference to
'123'. After reassigning d['a'] to point to the new object 'new
value', a new call to func() shows s still referencing the original
object and d['a'] referencing the new object. Is my comprehension of
these details correct? If yes, this is why I must constantly remind
myself that identifiers store references to objects, and that some
objects are mutable and some aren't, and these Python facts of life
are constantly challenging my old FORTRAN <= 77 ways of thinking...
~(:>))

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


Re: [Tutor] Need some help with setuptools for my project.

2015-04-07 Thread Cameron Simpson

On 08Apr2015 08:53, Anubhav Yadav  wrote:

Note the ":" before main, not ".".


That's it, that fixed the problem. Now I have a scorer binary.


No, you have a "scorer" executable which is a script. A "binary" is a loadable 
machine code file.



Thanks. A
couple of more questions!

1) If I have install_requires in setup.py, then do I need requirements.txt?


Probably not? I don't use this yet myself.


2) Can I run ``python setup.py install`` or ``python setup.py develop``
with root privileges? Just to test the app first?


Yes, but I would discourage it. It is too easy to tread on your platform's 
supplier packages this way. That can be bad, especially if you break something 
important for your OS.


Instead, I would advocate making a virtualenv iin your home directory into 
which you install your packages. You can make as many as you like.


After you've made a virtualenv, running the "pip" it supplies will install into 
the virtualenv. Much safer, and you can do it all as yourself.


Cheers,
Cameron Simpson 

I made this letter longer than usual because I lack the time to make it
shorter.- Pascal
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why is it invalid syntax to have a particular dictionary value as an argument?

2015-04-07 Thread Cameron Simpson

On 07Apr2015 21:16, boB Stepp  wrote:

Despite Mark's warning, I feel I must see if I understand what is going on here.

Switching to Py 3.4 since I am now at home:

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600
64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.

d = {'a': '123'}
def func(s=d['a']):

 print(s)
 print(d['a'])


func()

123
123

d['a'] = 'new value'
func()

123
new value

I added an additional print to the function to show the dictionary
entry's behavior.

First, my current understanding is that this form of the function does
not object to the presence of d['a'] in its parameter list because s
is the real parameter, d['a'] is its default value, but s is not
actually evaluated until run time.


Yes and no.

Yes to "s is the real parameter, d['a'] is its default value".

No to "s is not actually evaluated until run time".

When you _define_ the function, the _current_ value of d['a'] is stashed in the 
function definition as the default value.


When you _call_ the function, and omit the 's' parameter, the default value is 
used.


However, that value was _computed_ when the function was compiled: the function 
definition does not keep "d['a']" around for evaluation, instead that 
expression is evaluated when you define the function, and the reference to the 
resulting value kept around. That is thus '123'.


So when you go:

 d['a'] = 'new value'

the contents of the "d" dictionary have changed. But all that has happened is 
that the reference to '123' is no longer in the dictionary; instead a reference 
to 'new value' is in the dictionary.


When you call "func()" the name "s" is bound to the default value, which is the 
'123' as computed at function definition time. And it prints that. Of course, 
when you print "d['a']" it must evaluate that then, and finds 'new value'.


This is one reason why the common idion for default values looks like this:

 def func(s=None):
   if s is None:
 s = ... compute default here ...

Of course, the default is often a constant or some value computed earlier.

Cheers,
Cameron Simpson 

I think... Therefore I ride.  I ride... Therefore I am.
   - Mark Pope 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor