Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > simple perl program in python gives errors

Reply
Thread Tools

simple perl program in python gives errors

 
 
squash@peoriadesignweb.com
Guest
Posts: n/a
 
      01-30-2006
I am a little annoyed at why such a simple program in Perl is causing
so much difficulty for python, i.e:

$a += 200000 * 140000;

print $a;

 
Reply With Quote
 
 
 
 
kishkin
Guest
Posts: n/a
 
      01-30-2006
Maybe you should initialize a before using it?

 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      01-30-2006
On 2006-01-30, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:

> I am a little annoyed at why such a simple program in Perl is causing
> so much difficulty for python,


Ah, well, there's your problem. Python doesn't run Perl
programs. It runs Python programs. If you write your program
in Python instead of Perl, you'll not have such problems.

--
Grant Edwards grante Yow! If this was a SWEDISH
at MOVIE, I'd take off your
visi.com GO-GO BOOTS!!
 
Reply With Quote
 
Christoph Haas
Guest
Posts: n/a
 
      01-30-2006
On Monday 30 January 2006 17:52, (E-Mail Removed) wrote:
> I am a little annoyed at why such a simple program in Perl is causing
> so much difficulty for python, i.e:
>
> $a += 200000 * 140000;
>
> print $a;


a = 0
a += 200000 * 140000
print a

Seems to be more a problem for you than for Python.

Christoph

P.S.: Xah, is that you?
P.P.S.: You should have told what's going wrong.
P.P.P.S.: Variables are not automatically initialised in Python.
And you shouldn't even rely on that in Perl.
--
Never trust a system administrator who wears a tie and suit.
 
Reply With Quote
 
kishkin
Guest
Posts: n/a
 
      01-30-2006
Of course Grant Edwards is right, but I thought that your programm is
something like this:

------------------------
a += 200000 * 140000
print a
------------------------

and I thought that this is your perl program:
--------------------
$a += 200000 * 140000
print $a
--------------------

Funny if Grant Edwards is right...

 
Reply With Quote
 
squash@peoriadesignweb.com
Guest
Posts: n/a
 
      01-30-2006
i was hoping one didnt have to initialize variables because perl
defaults their value to zero. Also I noticed if I initialize a variable
as 0 , then I can only do integer math not floating math. this just
seems kind of backward as I am used to php and perl which dont require
such strict rules.

 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      01-30-2006
(E-Mail Removed) wrote:
> I am a little annoyed at why such a simple program in Perl is causing
> so much difficulty for python, i.e:
>
> $a += 200000 * 140000;
>
> print $a;
>

Yes, an annoying feature of the Python interpreter is that it doesn't
always interpret Perl correctly.

You will find, though, that

print 200000 * 140000

works quite well in both languages (with or without the trailing
semi-colon).

Variables in Python don't need a $ or @ to indicate whether they are
scalar or structured - that depends on their value.

So

a = 0
a += 200000 * 140000

should also work quite well. Note the first assignment is needed because
while there's no need to declare variables, you cannot assume a value
until they have been assigned one (in Pythonic jargon "bound to a value").

What does "+=" mean in Perl, by the way? Does it just assume $a is zero
if it isn't currently existent?

happily-forgotten-perl-ly y'rs - steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

 
Reply With Quote
 
John Zenger
Guest
Posts: n/a
 
      01-30-2006
(E-Mail Removed) wrote:
> Also I noticed if I initialize a variable
> as 0 , then I can only do integer math not floating math. this just
> seems kind of backward as I am used to php and perl which dont require
> such strict rules.
>


Not quite:

>>> foo = 0
>>> foo += 122
>>> print foo

122
>>> print foo / 7

17
>>> print foo / 7.0

17.4285714286
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      01-30-2006
On 2006-01-30, (E-Mail Removed) <(E-Mail Removed)> wrote:

> i was hoping one didnt have to initialize variables because perl
> defaults their value to zero.


Repeat after me: "Python is not Perl. Python is not Perl.
Python is not Perl. Python is not Perl. Python is not Perl.
Python is not Perl. Python is not Perl.Python is not Perl.
Python is not Perl. Python is not Perl. Python is not
Perl.Python is not Perl. Python is not Perl."

> Also I noticed if I initialize a variable
> as 0 , then I can only do integer math not floating math.


Python is a strictly typed language. Perl isn't -- Perl does
all sorts of stuff "automagically" by trying to guess what you
wanted". I perfer languages that do exactly what I tell them
to rather than what the language's author thought I might have
meant.

> this just seems kind of backward as I am used to php and perl
> which dont require such strict rules.


Really, and Perl/PHP seemed so primitive and backward to me. I
guess it's all in the perspective.

--
Grant Edwards grante Yow! Darling, my ELBOW
at is FLYING over FRANKFURT,
visi.com Germany...
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      01-30-2006
On Mon, 30 Jan 2006, Grant Edwards wrote:

> On 2006-01-30, (E-Mail Removed) <(E-Mail Removed)> wrote:
>
>> i was hoping one didnt have to initialize variables because perl
>> defaults their value to zero. Also I noticed if I initialize a variable
>> as 0 , then I can only do integer math not floating math.

>
> Python is a strictly typed language. Perl isn't -- Perl does all sorts
> of stuff "automagically" by trying to guess what you wanted". I perfer
> languages that do exactly what I tell them to rather than what the
> language's author thought I might have meant.


Especially when that's Larry Wall ...

tom

--
Don't trust the laws of men. Trust the laws of mathematics.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation debug=false in web.config gives errors in application Jonas ASP .Net 2 12-02-2010 05:41 PM
This seems to crash my program and gives me errors on the #include statements Eric_Dexter@msn.com Python 5 09-04-2006 06:53 PM
Embedding python: GCC gives errors of "undefined reference" to Py_* functions. Shuaib Python 1 08-19-2006 07:47 PM
VWD gives bogus validation errors unless MasterPageFile is specified in the @Page directive Alan Silver ASP .Net 1 02-23-2006 05:38 PM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM



Advertisments