Re: Request for help

2016-07-19 Thread MRAB

On 2016-07-19 22:21, alister wrote:

On Tue, 19 Jul 2016 13:06:39 +1000, Steven D'Aprano wrote:


On Tue, 19 Jul 2016 06:20 am, alister wrote:


I suggest next time you stay awake during lessons.


That's an uncalled for nasty comment. You don't know the O.P's issues or
why he is having difficulty.


because he has failed to provide any context.
the question as phrased looks exactly like a homework question a tutor
would set after a lesson introducing classes



It looked a lot like some posts from earlier this year.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Request for help

2016-07-19 Thread alister
On Tue, 19 Jul 2016 13:06:39 +1000, Steven D'Aprano wrote:

> On Tue, 19 Jul 2016 06:20 am, alister wrote:
> 
>> I suggest next time you stay awake during lessons.
> 
> That's an uncalled for nasty comment. You don't know the O.P's issues or
> why he is having difficulty.

because he has failed to provide any context.
the question as phrased looks exactly like a homework question a tutor 
would set after a lesson introducing classes



-- 
If you keep anything long enough, you can throw it away.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request for help

2016-07-19 Thread Steven D'Aprano
On Mon, 18 Jul 2016 07:50 pm, Eric kago wrote:

> Hi Pythoners
> 
> I need help in understanding hoe to put up the code to the following
> command

Hi Eric,

You might find that the "Tutor" mailing list is better for simple questions
like this:

https://mail.python.org/mailman/listinfo/tutor


Remember, for help with home work, show the code you already have.


>- Create a constructor that takes in an integer and assigns this to a
>`balance` property

Talking about a "constructor" means that you need to have a class. We define
a class with the "class" keyword:

class Myclass:
pass



To give it a constructor method, you need to use the __init__ method, or
sometimes __new__. In this case, I think __init__ is what you want. Do you
know how to define methods inside a class?

Remember that __init__ is spelled with TWO underscores at the start and end.




-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Request for help

2016-07-18 Thread Steven D'Aprano
On Tue, 19 Jul 2016 06:20 am, alister wrote:

> I suggest next time you stay awake during lessons.

That's an uncalled for nasty comment. You don't know the O.P's issues or why
he is having difficulty.



-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Request for help

2016-07-18 Thread alister
On Mon, 18 Jul 2016 12:50:04 +0300, Eric kago wrote:

> Hi Pythoners
> 
> I need help in understanding hoe to put up the code to the following
> command
> 
> 
>- Create a constructor that takes in an integer and assigns this to a
>`balance` property
> 
> 
> 
> 
> Regards,
> 
> Eric Kago +254(0)714249373 Nairobi Kenya

I suggest next time you stay awake during lessons.




-- 
I treasure this strange combination found in very few persons: a fierce
desire for life as well as a lucid perception of the ultimate futility of
the quest.
-- Madeleine Gobeil
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request for help

2016-07-18 Thread Eric kago
Hi Pythoners

I need help in understanding hoe to put up the code to the following command


   - Create a constructor that takes in an integer and assigns this to a
   `balance` property




Regards,

Eric Kago
+254(0)714249373
Nairobi
Kenya
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: request for help

2013-02-18 Thread Terry Reedy

On 2/18/2013 2:42 PM, leonardo selmi wrote:


i saved the above program from python shell into a file as "circle.py" .


Which copied too much into the file.
Edit circle.py until it is a proper python program.

My initial guess was that you copied the >>> prompts, but you later 
message shows that it was the welcome header. Header and prompts all 
need to go. Idle makes it easier to cut and paste a single statement 
from its shell to an editor window and then save. Or start your code in 
an editor, such as IDLE's.


--
Terry Jan Reedy

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


Re: request for help

2013-02-18 Thread Rick Johnson
leonardo  libero.it> writes:
> here is the error message:
> [...]

Okay, now we are on the road to solving this problem.

But first we need to take a slight detour and learn about python packaging,
because no matter what the current error is, naming a module "circle" and then
throwing it naked out into the "Python module wilderness" is complete folly; i
can assure you!


 What is a Python package?


A python package is simply another layer of namespace that protects our symbols
from clashing; in this case: module identifiers.

Even noobs understand that function bodies and class bodies (bka: object
definitions) protect code from outside influences, and that modules protect the
symbols contained in one module from the symbols contained in /other/ modules,
however, we still must protect module identifiers somehow. How do we do this?
Packages to the rescue!

Your "circle.py" module needs to be under the "protective care" of a specialized
package named "geom2d" , which itself should be under the care of a specialized
package named "math", which itself should be under the "global blanket" of a
personal library package named "insertUniqueNameHere"! This is how we protect 
module symbols whilst simultaneously employing a logical structure in our code.

 Impatient Ivan exclaimed: "So how the heck do i create the package Rick?"


Steps to create the entire package hierarchy:


Note: All package and modules names should be lowercase!

1a. Create a folder named "mylib" on the Python search path.
1b. Convert the "mylib" folder into a package by adding a file named:
"__init__.py" This will be your personal package for containing your personal
modules.

2a. Inside the "mylib" folder create another folder called "math"
2b. Convert the "mylib\math" folder to a package by adding a file named
"__init__.py".

3a. Inside the "mylib\math" folder create another folder named "geom2d"
3b. Convert the "mylib\math\geom2d" folder to a package by adding a file named
"__init__.py".

4. Inside the "mylib\math\geom2d" folder create a new file named "circlelib.py".
This is where you will place the code for computing circle data. Later you will
probably write something more useful, but for now this module is the best you 
have.

Now, you'll need to import the circlelib for use and this is how you do it:

## START CODE ##
from mylib.math.geom2d.circlelib import area, circumference
area(blah)
circumference(blah)
## END CODE ##

>From now on, if you create any more modules that deal with maths (or a subset 
>of
math: geom) you have a place to store them intelligently. There is quite a bit
more to Python packages but what i describe above is the most fundamental 
aspect.


 Back to your exception


Did correcting the indentation fix the problem? If not, what is the next error
you get?

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


Re: request for help

2013-02-18 Thread Gary Herron

On 02/18/2013 12:14 PM, leonardo wrote:

thanks guys and sorry for my incomplete datas, here is the error message:

Traceback (most recent call last):
  File "", line 1, in 
import circle
  File "circle.py", line 1
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43)
 ^
SyntaxError: invalid syntax


If I read this error message correctly,  I don't think the contents of 
circle.py are at all what you claim.  It looks like the first line of 
circle.py contains the text "Python 2.7.3 ..." which is certainly not 
what you intended or claimed. Please examine the contents of circle.py 
very carefully.






thanks for any help!






Il giorno 18/feb/2013, alle ore 20:59, Stefan Holdermans 
 ha scritto:


Leonardi,


i saved the above program from python shell into a file as "circle.py" . when i type 
"import circle" i get  error..


Next time, please mention what kind of error you're getting.

Was it an indentation error? Because, as you pasted it, your code would lead to 
one.

If I fix the indentation, as in

import math

def area(radius):
   return math.pi * radius**2

def circumference(radius):
   return 2 * math.pi * radius

it works fine for me.

HTH,

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


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


Re: request for help

2013-02-18 Thread leonardo

thanks guys and sorry for my incomplete datas, here is the error message:

Traceback (most recent call last):
 File "", line 1, in 
   import circle
 File "circle.py", line 1
   Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43)
^
SyntaxError: invalid syntax


thanks for any help!






Il giorno 18/feb/2013, alle ore 20:59, Stefan Holdermans 
 ha scritto:

> Leonardi,
> 
>> i saved the above program from python shell into a file as "circle.py" . 
>> when i type "import circle" i get  error..
> 
> 
> Next time, please mention what kind of error you're getting.
> 
> Was it an indentation error? Because, as you pasted it, your code would lead 
> to one.
> 
> If I fix the indentation, as in
> 
> import math
> 
> def area(radius):
>   return math.pi * radius**2
> 
> def circumference(radius):
>   return 2 * math.pi * radius
> 
> it works fine for me.
> 
> HTH,
> 
> Stefan
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: request for help

2013-02-18 Thread Stefan Holdermans
Leonardi,

> i saved the above program from python shell into a file as "circle.py" . when 
> i type "import circle" i get  error..


Next time, please mention what kind of error you're getting.

Was it an indentation error? Because, as you pasted it, your code would lead to 
one.

If I fix the indentation, as in

  import math

  def area(radius):
return math.pi * radius**2

  def circumference(radius):
return 2 * math.pi * radius

it works fine for me.

HTH,

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


Re: request for help

2013-02-18 Thread Gary Herron

On 02/18/2013 11:42 AM, leonardo selmi wrote:

pls i need help:

i have copied the following from a book and tried to make it work:

import math

def area(radius):
return math.pi * radius**2

def circumference(radius):
return 2 * math.pi * radius

i saved the above program from python shell into a file as "circle.py" . when i type 
"import circle" i get  error..


kind regards


First, you shouldn't ask us to help you fix an error without telling us 
what the error is!   You should also tell us what version of Python and 
what system (Windows? Linux? ...) , and anything more that can help us 
understand what you did and what failed.



So this is just guesswork:
Spaces are important in Python.  The body of a function **must** be 
indented.  If you do have the indents in your code, and they were just 
lost in the process of cutting and pasting and emailing, the we really 
do need more information.


def area(radius):
return math.pi * radius**2

def circumference(radius):
return 2 * math.pi * radius

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


Re: request for help

2013-02-18 Thread Rick Johnson
leonardo selmi  icloud.com> writes:
> [...]
> i saved the above program from python shell into a file as
> "circle.py" . when i type "import circle" i get  error..

Urm... would you be so kind as to copy and paste the error message verbatim? You
have obvious syntax errors in this code due to improper indentation, but take a
word of advice from the Python Zen:

 "In the face of ambiguity, refuse the temptation to guess"

So let's have a look-see at that error message, shall we?

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


Re: request for help

2013-02-18 Thread Matt Jones
Is this exactly how it shows in your shell?  If so, it seems you need to
indent your methods.

#
import math

def area(radius):
return math.pi * radius**2

def circumference(radius):
return 2 * math.pi * radius
#

*Matt Jones*


On Mon, Feb 18, 2013 at 1:42 PM, leonardo selmi  wrote:

> pls i need help:
>
> i have copied the following from a book and tried to make it work:
>
> import math
>
> def area(radius):
> return math.pi * radius**2
>
> def circumference(radius):
> return 2 * math.pi * radius
>
> i saved the above program from python shell into a file as "circle.py" .
> when i type "import circle" i get  error..
>
>
> kind regards
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Request for help with Image color space conversion

2008-01-06 Thread caca
>
> ...where the image data is loaded into a numpy array
> (1600x1200x3)...


One comment: that is a big array, too big for the cache memory. I know
that in these cases it makes a difference how many times the slices of
the array are loaded and unloaded from RAM onto cache. One issue is
that a 2D array l[i,j] is actually a 1D array:
either
l[i,j]=l[i*N+j]
or
l[i,j]=l[j*N+i]
I don't know which in python/numpy. In the first case, when you fix i
and change j, you get consecutive positions  in the underlying 1D
array, and they all belong to the same slice, which is loaded onto
cache very fast as a block. If you do the opposite, you are making
jumps to distant positions in the array (not a slice), and performance
suffers.

In gimp, for example, the underlying array is split into 'tiles',
which are 64x64 pixel regions that can be loaded/unloaded as a block.
And that's about all I know on the issue.

So it ma






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


Re: Request for help with Image color space conversion

2008-01-05 Thread Robert Kern
ttest wrote:
>> Reimplement colorsys.rgb_to_hsv() such that it operates on arrays instead of
>> scalars. Only minor modifications are necessary.
>>
>> --
>> Robert Kern
> 
> Thanks!  I'll try and see if a newcomer like me can get his head
> around the array-centric modifications to colorsys.

If you hit any roadblocks, drop in on numpy-discussion, and we'll help you out.

   http://www.scipy.org/Mailing_Lists

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


Re: Request for help with Image color space conversion

2008-01-05 Thread ttest
> Reimplement colorsys.rgb_to_hsv() such that it operates on arrays instead of
> scalars. Only minor modifications are necessary.
>
> --
> Robert Kern

Thanks!  I'll try and see if a newcomer like me can get his head
around the array-centric modifications to colorsys.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Request for help with Image color space conversion

2008-01-04 Thread Robert Kern
ttest wrote:
> Hello,
> 
> I'm working on an image processing project using the Python Imaging
> Library along with numpy.  Right now, I'm trying to build a speedy
> script for converting whole images between the RGB and the HSV (a.k.a.
> HSB) color spaces.  Unfortunately, the code I've made so far runs
> dreadfully slow with even moderate-sized images.
> 
> I'm under the impression that the crux of the problem is the fact that
> PIL's point method operates on only one band at a time, and to do a
> proper color space conversion, you need information about all three
> bands in a particular problem.  This has forced me to do an awkward
> work-around where the image data is loaded into a numpy array
> (1600x1200x3), and a dinky for-loop run runs through the array picking
> up RGB values, converting to HSV, and dumping the results back into
> another array.
> 
> How can I make this more efficient?

Reimplement colorsys.rgb_to_hsv() such that it operates on arrays instead of
scalars. Only minor modifications are necessary.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Request for help on naming conventions

2005-06-13 Thread Terry Hancock
On Monday 13 June 2005 03:59 am, Steven D'Aprano wrote:
> Are there any useful naming conventions for modules, classes and functions?
> 
> For instance, should I name functions as verbs and classes as nouns?

Hmm. Okay, here's a few I use:

Classes are generally: Capitalized  or CapWords  and I use nouns.
Unless it's a "mix-in" in which case, I use adjectives.  This mirrors
usage in the Zope sources, BTW.

Method names are either: funkyCaps (Zope uses this) or
lower_case_with_underscores.

I use verb names for methods and functions with very few exceptions.

I use nouns or occasionally adjectives for attributes.

Constants or enumeration values are ALLCAPS or ALL_CAPS, and
usually I define them within a namespace with a descriptive, all lower
case name (a trivial class).  The enumeration is usually abbreviated,
but would be an adjective, e.g.:

color.RED

I use *plural* names for lists and tuples, but singular names for
mappings.  This is so that I can use the singular in the loop:

for book in books:
pass

But I use single character variables in list comprehensions (and
generators, except I haven't used them yet):

late_books = [b for b in books if b.duedate < datetime.now()]

I also use single-character names in highly mathematical code:

def dot_product(a,b):
return a.x*b.x + a.y*b.y + a.z*b.z

But if a variable is going to be used more than about 20 lines
away from where it is defined, I use a descriptive word instead.

I like to use Capital or CapWords for modules, too, although I'm
beginning to wonder about that practice.

I really hate redundancy like this:

Topic.create_topic()

and usually prefer:

Topic.create()

which of course means, I have to qualify things a lot in my code.
This has never been an issue, but if it did, I would just introduce
an intermediary like this ("_" for "."):

Topic_create = Topic.create


After that, it's kind of case-by-case.  Do read PEP 8, too, of
course.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Request for help on naming conventions

2005-06-13 Thread Benjamin Niemann
Steven D'Aprano wrote:

> Are there any useful naming conventions for modules, classes and
> functions?
> 
> For instance, should I name functions as verbs and classes as nouns?
> 
> eg
> class Transformer():
> pass
> 
> def transform():
> do_stuff
> 
> What about the module name? transformations.py or transform.py?
You probably want to read the PEP 8, "Style Guide for Python Code":
http://www.python.org/peps/pep-0008.html


> What do people do with their own code? Do folks find that being
> consistent helps them remember what is what, or do you name objects
> whatever feels right at the time?
Naming convention are mostly a matter of personal taste (unless you are
working in a larger team, where there are some official conventions that
must be followed). So I would say the 'feels right' is the most important
factor.

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Request for Help in OpenSourcing a Project

2004-12-17 Thread fuzzylollipop
www.sourceforge.net

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