Re: [Tutor] Menus with dictionaries or lists?

2008-04-28 Thread Arthur
 http://www.amk.ca/python/howto/curses/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Menus with dictionaries or lists?

2008-04-28 Thread Arthur
#!/usr/bin/python
#

import csv
file = csv.reader(open("file.txt", "r"),delimiter=';')
for row in file:
 # now each row is a list
 #print row
 #print row[0]
 cntry=row[0]
 row[0]={}
 row[0]['country']=row[1]
 row[0]['county']=row[2]
 print 'for country',cntry,  row[0]

this is simple enough i guess, use your imagination to finish it up ...
to take input from user at cli you will use : raw_input("Enter Country")
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Best Practice/Style Guide question

2008-04-29 Thread Arthur
i like to write variable the kamelWay (i learned it from some javascript
book some time ago) but i never use spaces even in between :
variableName=variableValue.
i guess i like compact code with fewer lines ... always thought shorter
programs run faster... & it also makes you feel that your way it the
shortest smartest and fastest way ... since nobody can make it happen with
less code that yours ... ;)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Method question?

2008-05-02 Thread Arthur
i had tough time understanding classes ... hope this helps :
http://www2.lib.uchicago.edu/keith/courses/python/class/5/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting a .py file from Idle

2008-05-02 Thread Arthur
i guess :
START > RUN  then type : python your_script.py arg_1 arg_2
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting a .py file from Idle

2008-05-02 Thread Arthur
> On Fri, May 2, 2008 at 7:11 PM, Mihai Iacob <[EMAIL PROTECTED]> wrote:
> Hello,
>
>  Can anyone tell me how to start a program directly
> from the interpreter (i'm using IDLE). Usually i open
> a new window , write the lines of code and press F5 to
> run the program in the interpreter.
>  The problem is that i need to to that directly from
> the interpreter. (I'm running windows).


FILE > OPEN would open any text file & F5 would run any code in there.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Walking a directory

2005-01-17 Thread Arthur Wiebe
What I want to do is rather simple, but I cannot find any good
documentation for something like this.

The directory structure is sort of like this:
>Aircraft
>>A-10
+A-10cl-set.xml
+A-10fg-set.xml

For example Aircraft/A-10/A-10cl-set.xml

Now I want to loop though each aircrafts folder (such as A-10) and
find each *-set.xml file, get the aircraft part (such as A-10cl) and
add it to a list.

While this does seem simple, how is the question.

I know about the walk function, but cannot find any good examples for it.
-- 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] C API Tutorial Class Question

2007-05-03 Thread Arthur Coleman
I am using Windows XP and have successfully build the Boost libraries, plus
boost_python.dll.  I am trying to work through the C API tutorial where the
file hello.cpp is found at libs/python/example/tutorial.  I have been able
to compile and execute the first example building the supplied hello.cpp
file that allows Python to import a C function, but when I move onto the
next example in the tutorial:

 

struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};

 

#include 
using namespace boost::python;
 
BOOST_PYTHON_MODULE(hello)
{
class_("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}

 

 I replace the original contents of hello.cpp with the above code and using
bjam tried to build hello.pyd.  I receive the following errors:

 

...found 1513 targets...

...updating 4 targets...

vc-C++ bin\tutorial\hello.pyd\vc-8_0\debug\threading-multi\hello.obj

hello.cpp

hello.cpp(22) : error C2976: 'boost::python::class_' : too few template
arguments

G:\boost_1_33_1\boost/python/def_visitor.hpp(14) : see declaration
of 'boost::python::class_'

hello.cpp(22) : error C2440: '' : cannot convert from
'const char [6]' to 'boost::python::class_'

Source or target has incomplete type

hello.cpp(22) : error C2228: left of '.def' must have class/struct/union

hello.cpp(22) : error C2228: left of '.def' must have class/struct/union

hello.cpp(22) : error C2143: syntax error : missing ';' before '}'

 

CALL "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.BAT"
>nul

"C:\Program Files\Microsoft Visual Studio 8\VC\bin\cl" /Zm800 -nologo
/EHsc -c  -DBOOST_PYTHON_DYNAMIC_LIB /Z7 /Od /Ob0 /EHsc /GR /MDd
/Zc:forScope /Zc:wchar_t -I"bin\tutorial"  -I"G:\boost_1_33_1"
-I"c:\Python25\include"
-Fo"bin\tutorial\hello.pyd\vc-8_0\debug\threading-multi\hello.obj"
-Tp"hello.cpp"

 

...failed vc-C++
bin\tutorial\hello.pyd\vc-8_0\debug\threading-multi\hello.obj...

...skipped <@tutorial\hello.pyd\vc-8_0\debug\threading-multi>hello.CMD for
lack of <@tutorial\hello.pyd\vc-8_0\debug\threading-multi>hello.obj...

...skipped <@tutorial\hello.pyd\vc-8_0\debug\threading-multi>hello.pyd for
lack of <@tutorial\hello.pyd\vc-8_0\debug\threading-multi>hello.CMD...

...skipped <@tutorial\hello.pyd\vc-8_0\debug\threading-multi>hello.lib for
lack of <@tutorial\hello.pyd\vc-8_0\debug\threading-multi>hello.CMD...

...failed updating 1 target...

...skipped 3 targets...

 

I reviewed the definition of class_ in file def_visitor.hpp and found that
it was defined as:

 

template class class_;

 

I have tried searching the FAQ and the Web and so far no luck.  I would
appreciate any help.

 

Arthur

 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Arthur Coleman
Hi,

I believe it should be if !(year % 4) or !(year % 100) or !(year % 400)

Since 4*n % 4 = 0 for n integer

Arthur

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Luke Paireepinart
Sent: Monday, May 14, 2007 2:32 PM
To: Matt Smith
Cc: Python Tutor
Subject: Re: [Tutor] How to test for a remainder from division

Matt Smith wrote:
> Hi there,
>
> I'm trying to write a short function to test whether a year is a leap
> year or not. To do this I need to check whether the year divides exactly
> by 4, 100 and 400. I can't think of an easy way to test whether there is
> a remainder or not. The best I can come up with so far is:
>
> if (year / 4.0) - (year // 4.0) <> 0:
>
> This doesn't seem to work, it is always True, is there a problem with
> the comparison? The arithmetic seems to be the correct way to isolate
> the remainder of the division.
>
> Can anyone suggest a better way of performing this test or alternately,
> how can I get the line above to work.
> Matt
>   
Matt:  I'm not sure about your pseudocode, but have you tried to 
accomplish this with the modulus operator?
It provides the remainder of integer division (i.e. a remainder of 0 
indicates a perfect divisor.)
so you could do:
if year % 4 or year % 100 or year % 400: #then it's divisible perfectly 
by any of [4,100,400]
for example.
HTH,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python simplejson decoding

2011-03-02 Thread Arthur Mc Coy
Hi all,



I'm trying an example (in attached file).

First, I create a list of 3 objects. Then I do:


PutJSONObjects(objects)
objects = GetJSONObjects()
PutJSONObjects(objects, "objects2.json")


1) PutJSONObjects(objects) method creates objects.json file (by default). It
works fine.
2) Then objects = GetJSONObjects() method get the file contents and return.

3) Finally the script fails on the third method PutJSONObjects(objects,
"objects2.json")
saying: AttributeError: 'dict' object has no attribute '__dict__'


That is true, because objects returned by GetJSONObjects() is not a list of
objects, but simple string

So here is the question, please, how should I DECODE .json file into list of
python objects so that I will be able to put the copy of these objects into
a new file called objects2.json ?

simplejson  docs are hard to
follow - without examples.



Please, help me. Be happy!

Bart


cache.py
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] c++ data types in python script

2011-03-06 Thread Arthur Mc Coy
Hi people,

I've used SWIG module to embed python inside c++ app. I pass a list of
objects (with lots of different properties of types string, float,
custom types like URL, Software and finally of list of strings).

Now I'm in python. URL and Software has str() method that converts
their value to string recognizable by JSON. But the problem is with
list of strings.

So, as I said I passed std::list myObjects to python
function.
Then I iterate it and for each object in myObjects I create a python
copy (serialize it) to be able to put into JSON format and store in
appropriate file.

object has property benchmarks of type list.
I do:
...
class PythonObject:
def __init__(self, object):
self.benchmarks = list()
for s in object.benchmarks:
self.benchmarks.append(s)
...
and it fails, also I do:
...
class PythonObject:
def __init__(self, object):
self.benchmarks = [unicode(s) for s in object.benchmarks]
...
and it fails, also I do:
...
class PythonObject:
def __init__(self, object):
for s in object.benchmarks:
print s[0] + s[1] + s[2]
print type(s)
...
and it fails printing
   wor
   
   Segmentation fault (core dumped)
$
also I do:
...
class PythonObject:
def __init__(self, object):
self.benchmarks = unicode(object.benchmarks)
...
and it does not fail, instead it puts in JSON this string:
...
"benchmarks": " > *' at
0xb63ed4e8>>",
...
but it is not what I need

What I'm trying to stress is that c++ objects should be converted
(serialized) before putting them into json. Otherwise type errors
occur and process fails.

I love learning python and hope somebody may suggest me or tell
something.

Thank you all anyway!
Arthur
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] c++ data types in python script

2011-03-06 Thread Arthur Mc Coy
Thank you, sorry for duplicating. I hope moderators can delete it if needed.

Wish you well,
Arthur

On Sun, Mar 6, 2011 at 11:18 AM, Stefan Behnel  wrote:

> Arthur Mc Coy, 06.03.2011 09:56:
>
>  I've used SWIG module to embed python inside c++ app.
>>
>
> Given that this deals with an advanced topic (C-level extensions), I find
> comp.lang.python (python-list), where you also posted this, a more
> appropriate place for discussion than the Python tutor mailing list. So I
> suggest people answer on c.l.py.
>
> Stefan
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor