OOP: How to implement listing al 'Employees'.

2007-12-28 Thread Petar
I was just wondering.

What if you have a 'Employees' class and you want to list all the
employees. Currenlty i'm seeing to possibilities:

- create a 'listAll' function inside the class which returns all the
employees in a array.
- create multiple instances, putting them in a array, by calling the
Employees class multiple times in a loop (thus not creating a listAll
function in the class).

What is the better way of doing this? And should a class always
reference only on 'item'?

Thank in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP: How to implement listing al 'Employees'.

2007-12-28 Thread Petar
On 28 dec, 13:40, Bjoern Schliessmann  wrote:
> Petar wrote:
> > What is the better way of doing this? And should a class always
> > reference only on 'item'?
>
> It fully depends on what you want to do in your program. If you just
> want to have a list of employees, a list or dict will suffice. If
> you need a full-fledged employee database, an "Employees" class may
> be a good API.
>
> Regards,
>
> Björn
>
> --
> BOFH excuse #83:
>
> Support staff hung over, send aspirin and come back LATER.

It's a pure hypothetical question about where to put the function for
the list of employees when already having a Employee class.

Do I make it a method of the class, or do i create a instance of the
class for every employee (sitting inside a list)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP: How to implement listing al 'Employees'.

2007-12-29 Thread Petar
On 28 dec, 19:42, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Fri, 28 Dec 2007 04:05:59 -0800 (PST), Petar <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
> > I was just wondering.
>
> > What if you have a 'Employees' class and you want to list all the
> > employees. Currenlty i'm seeing to possibilities:
>
> > - create a 'listAll' function inside the class which returns all the
> > employees in a array.
> > - create multiple instances, putting them in a array, by calling the
> > Employees class multiple times in a loop (thus not creating a listAll
> > function in the class).
>
> > What is the better way of doing this? And should a class always
> > reference only on 'item'?
>
>         Bottom-up responses...
>
>         Unless you are contaminated by Java's need for a class to hold
> static functions, classes are just templates for an undefined object.
> You create an instance of the class to create a defined object. It is
> not common in Python to create a class that is not meant to be
> instantiated at least once (something that is just static methods is
> probably easier implemented as an import module with plain functions and
> module level globals).
>
>         Now, by "name", an "Employees" (plural s) class, to me, implies a
> class to represent a group of employees -- as a group! It would NOT have
> methods or members (both of which are just attributes in generic Python
> hissing) that refer to information about any specific employee -- such
> information should be part of an "Employee" (no S) class.
>
> aDept = Employees(dept="Finance")
> aDept.manager = Employee(name="John Dont", ID=3141596, phone="123-4567")
> aDept.addEmployee(Employee(name=))
> aDept.addEmployee(Employee(...))
> ...
>         Note that this does not enforce any particular storage concept. The
> Employees (with the S) class could be using a list to store each
> employee, or a dictionary (maybe keyed by ID), or even an RDBM with a
> join (where one has tables for, say, department, employee, and
> intersection linking department to employee):
>
> select e.* from employees as e
> inner join dept_employee as de
> on de.empID = e.ID
> inner join departments as d
> on d.id = de.deptID
> where d.name = "Finance";
>
> aBody = aDept.employee(id=)
>
> aDept.removeEmployee(id=...)
>
> aDept.printEmployees()
>
>         If all you need is a "list" of raw employees, with no meaning
> associated to the list... Then just use a list...
>
> aList = []
> aList.append(Employee(name=...))
> aList.append(Employee(...))
>
> for e in aList:
>         e.printEmployee()
> --
>         Wulfraed        Dennis Lee Bieber               KD6MOG
>         [EMAIL PROTECTED]             [EMAIL PROTECTED]
>                 HTTP://wlfraed.home.netcom.com/
>         (Bestiaria Support Staff:               [EMAIL PROTECTED])
>                 HTTP://www.bestiaria.com/

I'm sorry if my question wasn't clear enough. But I think it has been
answered.

Let me explain how I got to this question. I had written een Article
class which handled the articles that I had. On a certain page I
wanted to show all the articles. That got me wondering about what to
do. Should I make a method in my Article.class which returned multiple
articles, or should I just use my current Article.class and fill a
list (with a loop) with articles. The first solution thus meaning
writing another method, the latter method to just use the current
Article.class and call it multiple times.

The post of Dennis made me realize of another solution though. To
create another class called Articles which return multiple articles.
The only problem I forsee with this that's it's gonna be a very empty
class.

Thank you all for your response, it has pointed me in the right
direction.



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


Is it possible to use Google's advanced search options?

2010-11-20 Thread Petar Milin

Hello!
Can anyone help me with getting number of hits from Google, but with 
restricton on domain (e.g., .edu) and language (e.g., lang_de)? I have 
tried with the Pygoogle (from: http://code.google.com/p/pygoogle/ 
): 


from pygoogle import pygoogle
word = u'something'
request_word = word.encode('utf-8')
request = ('%s+site:.edu' % request_word)
g = pygoogle(request)
g.get_result_count()


Now, I realized that domain restriction works, but language does not, 
since it cannot be specified in request like domain in example above.
Please, help! Is this possible with the Pygoogle? If not, how can I make 
that happen?


Thanks!
PM


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


Re: Python-list Digest, Vol 86, Issue 176

2010-11-20 Thread Petar Milin
Thanks so much! However, 'options lang:de' does not exactly the same
as would 'lr=lang_de'? Am I right?
Since I need number of hits, I would like to have the best, most
correct values! :-)

Sincerely,
PM

On Sat, Nov 20, 2010 at 12:00 PM,   wrote:
> Send Python-list mailing list submissions to
>        [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mail.python.org/mailman/listinfo/python-list
> or, via email, send a message with subject or body 'help' to
>        [email protected]
>
> You can reach the person managing the list at
>        [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-list digest..."
>
> Today's Topics:
>
>   1. Re: what's the precision of fractions.Fraction? (Mark Dickinson)
>   2. Re: Is it possible to use Google's advanced search options?
>      (Stefan Sonnenberg-Carstens)
>
>
> -- Forwarded message --
> From: Mark Dickinson 
> To: [email protected]
> Date: Sat, 20 Nov 2010 01:46:33 -0800 (PST)
> Subject: Re: what's the precision of fractions.Fraction?
> On Nov 19, 3:29 pm, RJB  wrote:
>> Does Fractions remove common factors the way it should?
>>
>> If it does and you want to find the closest fraction with a smaller
>> denominator i think tou'll need some number theory and continued
>> fractions.
>
> Or perhaps just use the existing Fraction.limit_denominator method
> (which does indeed use some number theory and continued fractions):
>
>>>> from fractions import Fraction
>>>> from math import pi
>>>> Fraction.from_float(pi).limit_denominator(1000)
> Fraction(355, 113)
>
> --
> Mark
>
>
>
> -- Forwarded message --
> From: Stefan Sonnenberg-Carstens 
> To: [email protected]
> Date: Sat, 20 Nov 2010 11:30:44 +0100
> Subject: Re: Is it possible to use Google's advanced search options?
> Am 20.11.2010 10:37, schrieb Petar Milin:
>
> Hello!
> Can anyone help me with getting number of hits from Google, but with 
> restricton on domain (e.g., .edu) and language (e.g., lang_de)? I have tried 
> with the Pygoogle (from: http://code.google.com/p/pygoogle/):
> from pygoogle import pygoogle
> word = u'something'
> request_word = word.encode('utf-8')
> request = ('%s+site:.edu' % request_word)
> g = pygoogle(request)
> g.get_result_count()
>
> Now, I realized that domain restriction works, but language does not, since 
> it cannot be specified in request like domain in example above.
> Please, help! Is this possible with the Pygoogle? If not, how can I make that 
> happen?
>
> Thanks!
> PM
>
> See below
>
> word = u'something'
> request_word = word.encode('utf-8')
> request = ('%s site:.edu options lang:de' % request_word)
> g = pygoogle(request)
> g.get_result_count()
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to use Google's advanced search options?

2010-11-21 Thread Petar Milin

Hello!
Thanks so much for the patched Pygoogle!
Also, please, can you give me some more information about how to use 
google search api?
I am a newbie in Python, and I still try to cope with it. Thanks to some 
experience in other
programing languages, I think I progress well, but I am not a 
professional user/programer;

quite far from that.

Best,
Petar

On 20/11/10 21:27, Stefan Sonnenberg-Carstens wrote:

Am 20.11.2010 20:24, schrieb Petar Milin:

Thanks so much! However, 'options lang:de' does not exactly the same
as would 'lr=lang_de'? Am I right?

You're right.

Since I need number of hits, I would like to have the best, most
correct values! :-)

Sincerely,
PM

On Sat, Nov 20, 2010 at 12:00 PM,  
wrote:

I took a look into pygoogle source code.
It does not send the 'lr' parameter to google.de (as it does not with 
many more ...).

I patched it to enable the following (what you needed):

>>> from pygoogle import pygoogle
>>> g = pygoogle('linux site:.edu')
>>> g.lr = 'lang_de'
>>> g.pages = 2
>>> print 'German',g.get_result_count()
German 3910
>>> g.lr = 'lang_en'
>>> print 'English',g.get_result_count()
English 114
>>> g.lr = 'lang_cn'
>>> print 'Chinese',g.get_result_count()
Chinese 121
>>>

I have attached my patched version of pygoogle.
BTW: the google search api is very straight forware.
Perhaps it is easier to create a custom bot to do your queries.
Cheers,


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


Re: Does Pygoogle allows for advanced search options?

2010-11-21 Thread Petar Milin


On 20/11/10 22:34, Chris Rebert wrote:

On Thu, Nov 18, 2010 at 3:26 AM, neocortex  wrote:
   

The library doesn't seem to have built-in support for filtering by
language (and Google lacks a search query-string-based operator for
that), but it looks like you could implement that feature by adding an
"lr" parameter with an appropriate value to the query `args`
dictionary. See the "lr?" entry under "Web Search Specific Arguments"
onhttp://code.google.com/apis/websearch/docs/reference.html, and
lines 68&  102 of pygoogle.py.
   

 From those lines, it can be concluded that lr=lang_?? is not
supported, unfortunately.
 

Right; that's why I said "you could implement that feature". Pretty
easily it would seem.
   
Thanks for believing in me ( ;-) ), but I am a newbie in Python world, 
although with some experience in other prog. languages.
So, if I read pygoogle.py well, I sould add lr parameter in init and 
then after lines 68 and 102?


Thanks again! You guys here are very kind and helpful!
Best,
Petar

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


Re: Does Pygoogle allows for advanced search options?

2010-11-21 Thread Petar Milin

Hello ALL!
I am playing with the modified version of the Pygoogle (by Stefan). 
Interesting thing is that get_result_count() gives numbers/results 
different from those in Google. Has anyone checked this? Does anyone 
know why?


Best,
Petar
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Pygoogle allows for advanced search options?

2010-11-21 Thread Petar Milin
So, what can one do about this? There seems to be at least two aspects: (a) 
difference between browser-based and script-based (pygoogle in this case) 
query, and (b) difference in time and place, but possibly within the same query 
type. If so, how can we be sure? It would be interesting (at least to me) to 
check for the correlations between numbers. That would answer whether there is 
some/any consistency.

Best,
Petar

- Original message -
> Am 21.11.2010 20:35, schrieb Petar Milin:
> > Hello ALL!
> > I am playing with the modified version of the Pygoogle (by Stefan). 
> > Interesting thing is that get_result_count() gives numbers/results 
> > different from those in Google. Has anyone checked this? Does anyone 
> > know why?
> > 
> > Best,
> > Petar
> > 
> AFAIK there are several reports which point to the same observation;
> even time & location (requesting IP) seem to generate different results.
> 
> 

   stefan_sonnenberg.vcf

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