Programmer's text editor, for Python and everything else (was: IDE for python)

2014-05-28 Thread Ben Finney
Greg Schroeder gmschroe...@gmail.com writes:

 Any gripes against vim with some tweaks?

None from me; Vim is a fine programming (and programmable) editor.

It is free software, like Python. This is vital for any tool in which
one expects to sink an amount of effort. It means no party has
privileged access to change it, which ensures that (unlike proprietary
software) it will never be held hostage to one party's disinterest or
whim.

It works the same way on all important operating systems today that
programmers will use to write programs. This is, of course, a result of
it being free software; anyone motivated to improve the software on a
particular platform has full freedom to do so, and return the
improvements to the community.

It is mature and highly flexible, both of which mean it can handle any
important programming task once someone puts in the effort to configure
it. And it has a thriving community, which means most of what you want
customised has already been done by others.

It supports a massive range of text editing tasks, most of which you
don't need to know but will be there when your programming tasks expand
as they inevitably do. You won't need to re-learn another tool, but only
a plug-in for your existing text editor.


All of the above are true for Vim and Emacs, which is why I strongly
recommend learning one of them well and using it for all the editing you
do while programming.

URL:https://wiki.python.org/moin/Vim
URL:http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/

URL:https://wiki.python.org/moin/EmacsEditor
URL:http://www.enigmacurry.com/2008/05/09/emacs-as-a-powerful-python-ide/

-- 
 \   “When a well-packaged web of lies has been sold to the masses |
  `\over generations, the truth will seem utterly preposterous and |
_o__)its speaker a raving lunatic.” —Dresden James |
Ben Finney

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


Can not find a file in CMD model python when everything is OK in IDLE

2006-03-11 Thread Sullivan WxPyQtKinter
I use python in Windows XP platform. I find that if I write a .py file
in a directory, such as windows desktop, in which a file named
'ticket.txt' is located:

f=open(\ticket.txt)
print f.read()

In IDLE, this py file work all right. But if I launch python
interpretor in the command shell like this:

C:\Documents and Settings\Xiaozhong Zhengpython C:\Documents and
Settings\Xiao
zhong Zheng\Desktop\t.py

The interpretor would not find the file.

Traceback (most recent call last):
  File C:\Documents and Settings\Xiaozhong Zheng\Desktop\t.py, line
1, in ?
f=open(ticket.txt)
IOError: [Errno 2] No such file or directory: 'ticket.txt'

Anyone knows why?


In addition, if I start IIS web service that runs .py file as CGI
program, then this .py file also works.

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


Can not find a file in CMD model python when everything is OK in IDLE

2006-03-11 Thread Sullivan WxPyQtKinter
I use python on Windows XP platform. I find that if I write a .py file
in a directory, such as windows desktop, in which a file named
'ticket.txt' is located:

f=open(ticket.txt)
print f.read()


In IDLE, this py file work all right. But if I launch python
interpretor in the command shell like this:


C:\Documents and Settings\Xiaozhong Zhengpython C:\Documents and
Settings\Xiaozhong Zheng\Desktop\t.py


The interpretor would not find the file.


Traceback (most recent call last):
  File C:\Documents and Settings\Xiaozhong Zheng\Desktop\t.py, line
1, in ?
f=open(ticket.txt)
IOError: [Errno 2] No such file or directory: 'ticket.txt'


Anyone knows why?


In addition, if I start IIS web service that runs .py file as CGI
program, then this .py file also works.

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


Re: Can not find a file in CMD model python when everything is OK in IDLE

2006-03-11 Thread Fredrik Lundh
Sullivan WxPyQtKinter wrote:

 I use python in Windows XP platform. I find that if I write a .py file
 in a directory, such as windows desktop, in which a file named
 'ticket.txt' is located:

 f=open(\ticket.txt)
 print f.read()

\t is a tab character:

 print '\ticket.txt'
icket.txt

try opening r\ticket.txt or /ticket.txt instead.

/F



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


Re: Can not find a file in CMD model python when everything is OK in IDLE

2006-03-11 Thread Sullivan WxPyQtKinter
Sorry, I mistyped the line. In the program it IS:
f=open(ticket.txt), no '\' included.

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


Re: Can not find a file in CMD model python when everything is OK in IDLE

2006-03-11 Thread Fredrik Lundh
Sullivan WxPyQtKinter wrote:

 In IDLE, this py file work all right. But if I launch python
 interpretor in the command shell like this:


 C:\Documents and Settings\Xiaozhong Zhengpython C:\Documents and
 Settings\Xiaozhong Zheng\Desktop\t.py

 The interpretor would not find the file.

open(ticket.txt) means look for ticket.txt in the current directory,
not in the directory where the PY file lives.  if you change to the Desk-
top directory before you run the Python interpreter, your script should
work as expected.

to fix this, you can

- use a full path

or

- use os.path.basedir(__file__) to get the directory where the module
  lives, and do something like

root = os.path.basedir(__file__)
ticketfile = os.path.join(root, ticket.txt)
f = open(ticketfile)

/F



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


Re: Can not find a file in CMD model python when everything is OK in IDLE

2006-03-11 Thread Sullivan WxPyQtKinter
I see. I once was a VB programmer. In VB, the current directory is
always set to where the module locates before it runs.

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


Re: Can not find a file in CMD model python when everything is OK in IDLE

2006-03-11 Thread Sullivan WxPyQtKinter
I see. I once was a VB programmer. In VB, the current directory is
always set to where the module locates before it runs.

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


Re: Python for everything?

2005-07-03 Thread Joseph Garvin
Larry Bates wrote:

poorly.  When new version of Python ships, you just learn what is new.
If you try to keep up with C, C++, Visual Basic, ... it gets to be
impossible.

Hope information helps.

Larry Bates

  

Huh? Part of C++'s problem is that it takes too long for obvious good
stuff to get into the language. It stays the same for years at a crack
inbetween the committees approving stuff. Python in contrast can see a
release every few months.

Python is a moving target. C++ is not.

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


Re: Python for everything?

2005-07-03 Thread Joseph Garvin
Mike Meyer wrote:

You wind up
having to invoke the function through your data object, and then pass
the data object in - sort of as an explicit self.

  

Yeah, and us pythonists hate explicit self! ;)

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


Re: Python for everything?

2005-07-03 Thread Mike Meyer
Joseph Garvin [EMAIL PROTECTED] writes:

 Mike Meyer wrote:

You wind up
having to invoke the function through your data object, and then pass
the data object in - sort of as an explicit self.

 Yeah, and us pythonists hate explicit self! ;)

Except the explicit self is on the method invocation, and not in the
method definition! So you wind up repeating the variable name.

   mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-07-02 Thread TZOTZIOY
On Thu, 30 Jun 2005 20:55:20 -0400, rumours say that Mike Meyer
[EMAIL PROTECTED] might have written:

Actually, I was thinking of pre-KR Unix compilers.

There must be something I am missing here, cause I don't understand what
you mean; what is the earliest KR C compiler (Unix compiler) you
consider as such?  Were there other Unix C compilers before KR wrote
one?  Or are you considering as KR Unix compilers those after the
publication of the white book and before C89?
-- 
TZOTZIOY, I speak England very best.
Dear Paul,
please stop spamming us.
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-07-02 Thread Roy Smith
Christos TZOTZIOY Georgiou [EMAIL PROTECTED] wrote:
 Were there other Unix C compilers before KR wrote one? 

Considering that KR (along with T) invented both Unix and C, I would say 
that the answer to the above has to be No.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-07-02 Thread Mike Meyer
Christos TZOTZIOY Georgiou [EMAIL PROTECTED] writes:

 On Thu, 30 Jun 2005 20:55:20 -0400, rumours say that Mike Meyer
 [EMAIL PROTECTED] might have written:

Actually, I was thinking of pre-KR Unix compilers.

 There must be something I am missing here, cause I don't understand what
 you mean; what is the earliest KR C compiler (Unix compiler) you
 consider as such?  Were there other Unix C compilers before KR wrote
 one?  Or are you considering as KR Unix compilers those after the
 publication of the white book and before C89?

The latter. I was considering KR Unix compilers to be the compiler
described by the white KR book - what is basically the v7 Unix C
compiler. Thwe v6 compiler didn't do op=, it still did =op. We used the
photo7 C compiler on our v6 system. I don't believe that was written by
KR.

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-07-01 Thread Tom Anderson
On Thu, 30 Jun 2005 [EMAIL PROTECTED] wrote:

 can Python do it all?

More or less. There are two places where python falls down, IMHO. One is 
performance: python isn't generally as fast as C or Java, even with Psyco. 
However, the number of cases where performance - and absolute 
straight-line performance of the code - actually matters is much smaller 
than you might think. Also, you can incorporate C into python pretty 
easily. The other is in bit-twiddling - anything that involves mucking 
about with data at the level of bits and bytes. Maybe this is just blind 
prejudice, but i'm never as comfortable hacking on that sort of stuff 
(writing a Huffman coder, say) in python as in java.

Other than that, python is pure victory.

 I am wondering what to learn as my scripting language.

Python.

 I have read that perl is good up to about 250 lines, and after that it 
 gets kind of hairy.

That's putting it mildly.

 I would like opinions as to the suitability of Python as a general 
 purpose language for programming unix, everything from short scripts to 
 muds.

Python is, all things considered, definitely the best such language.

There are strong arguments that can be made in favour of younger cousins 
of Python such as Ruby and Lua, but none of those have anything like the 
userbase or third-party code that Python does, and that counts for a lot. 
LISP (or rather Scheme) would be a more unusual option; it's a language 
that most people hate, but that people who really take the time to learn 
it love with a fervour bordering on scary.

tom

-- 
In-jokes for out-casts
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-07-01 Thread Luis M. Gonzalez
Let me express it with an exaple (by the way, sorry for my bad
english):
Suppose you are planning to build a house.
You have two choices:
- Option one: Buy several thousands bricks, doors, tiles, windows,
etc... put them all together according to the blueprints and build your
home.
- Option two: Get loads of sand, concrete, wood and raw materials, make
your own bricks, make each door and windows with your prefered kind of
wood, design and make your tiles, etc.. and after a long, long time,
create a unique, one of a kind house.

Option one would be like using Python for creating your programs.
It gives you all the built-in functions and high level data structures
with which you can create a solution for almost any kind of problem you
might want to solve. You don't have to spend time allocating memmory,
using pointers, creting your data structures from scratch, etc, etc..
because it's all there already available for you, and all these time
consuming, error-prone tasks are very well hadled by python itself.

Option two is like using C:
It gives you full control in the creating on your program, but 90% of
the times (or more) you might think do I really need to go through all
this hassle?. Sure, it will be faster but, do I really need this
extra speed?.

I think that with the current processors, speed and performance is less
an isue than it was a few years ago.
Most of the times, developing time is paramount. And even if you need
very good execution speed for a given task, you can still code an
extension in c or c++ and keep all the benefits of a high level
programming language such as python.

And if these arguments still can't convince you, be adviced that
there's a very ambicious and exciting project called Pypy which aims
to create a high performance python implementation, and it is being
developed very succesfully.
They say that the secret goal is being faster than c... and I'm not
sure but I think that there's a tentative hard line set to december of
2006. Check it out: http://codespeak.net/pypy/index.cgi?news

Cheers,
Luis

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


Re: Python for everything?

2005-07-01 Thread Grant Edwards
On 2005-06-30, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 I have read in the old days that C was used for everything. It
 was a systems programming language, and also did a lot of the
 same stuff Bash scripts and perl do now.

Not really.  C was used for a lot of stuff (mostly just under
Unix), but there was still tons of COBOL, FORTRAN, Lisp, and a
bunch of other languages.  Under Unix bourne shell (from which
bash evolved) has always been popular for scripting.  Sed and
awk scripts have been popular for ages as well.  Other OSes
have various JCL and batch scripting languages. C was only
popular under Unix OSes -- under most other OSes, C wasn't
popular at all.  MacOS and Windows APIs were originally
designed for use by Pascal, VAX/VMS was apparently intended to
be used via FORTRAN and BLISS-32.  C was later made available
on those platforms but you could tell it didn't really fit
well with the OS.

 So, in that era, C did it all, from short to tall.

My memory only goes back about 25 years, but that was never
true in my experience.

 My question is, can Python do it all? I am wondering what to
 learn as my scripting language.

First, stop thinking in the singular.  For starters I'd
recommend bash, Python, and awk.  Add perl if you like, but I
think it's syntax/semantics are extraordinarily nasty (I even
find the Lisp family of languages far easier to read).

 I have read that perl is good up to about 250 lines, and after
 that it gets kind of hairy.

In my experience it get's hairy a lot faster than that. :)

 However, from what little I have heard about Python, it's very
 well suited for readability due to the whitespace requirements
 of the language, and very good for large projects due to it's
 large amount of modules and it's object oriented structure.

True.

 I would like opinions as to the suitability of Python as a
 general purpose language for programming unix, everything from
 short scripts to muds.

I use Python for all sorts of programs under from a couple
lines for a normal text filter to thousands of lines with a
complex GUI.  

[Why are Python programs referred to as scripts. Python no
more a scripting language than Java, Pascal, Smalltalk,
Objective C.]

-- 
Grant Edwards   grante Yow!  Yow! We're going to
  at   a new disco!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-07-01 Thread Grant Edwards
On 2005-06-30, Ivan Van Laningham [EMAIL PROTECTED] wrote:

 As other have noted, C was never really used for everything. Unix
 tools were designed to connect together from the very beginning, which
 is what makes shell scripting so powerful. This was true before there
 was a C. Likewise, some things you need more control over the machine
 than you get in C - those are still done in assembler. These days, C
 compilers let you embed assembler statements in your C, so some of
 these things are done in such variants.

 It really was used for everything;

I think there are two intepretations of C being used for
everthing.  

My reading of that phrase is that nothing else was used: there
were no shell scripts, no awk scripts, no FORTRAN programs, no
JCL, no COBOL, no Lisp, no sed.

That just was never the case.  There never was a C-language
monoculture in any OS.

Another possible interpretation is that at some point in the
past, there was some misguided soul who has tried to use C for
every type of task imaginable.  That's probably true, but the
same could be said of any language.

-- 
Grant Edwards

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


Re: Python for everything?

2005-07-01 Thread Peter Hansen
Grant Edwards wrote:
 [Why are Python programs referred to as scripts. Python no
 more a scripting language than Java, Pascal, Smalltalk,
 Objective C.]

I think it's because the term script is a nice, simple word that 
evokes the idea of source file that can be directly executed, which is 
a convenient thing to be able to say in fewer words than that...

I think it would be unusual for anyone to refer to a multi-file Python 
program as merely a script.

We do often call individual source files in a large Python program 
scripts, but I think that's probably just out of habit or association: 
calling single Python source files scripts is so common, even if they 
aren't scripts in the sense of individually executable files written in 
a scripting language any more.

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


Python for everything?

2005-06-30 Thread xeys_00
I posted a article earlier pertaining programming for my boss. Now I am
gonna ask a question about programming for myself. I just finished my
first C++ Class. Next semester is a class on encryption(and it's
probably gonna be a math class too). And finally back in programming in
the fall with C++ and Java 1. The C++ will cover pointers, and linked
lists, sorting algorithms, etc... I run linux and OS X. I have read in
the old days that C was used for everything. It was a systems
programming language, and also did a lot of the same stuff Bash scripts
and perl do now. So, in that era, C did it all, from short to tall. My
question is, can Python do it all? I am wondering what to learn as my
scripting language. I have read that perl is good up to about 250
lines, and after that it gets kind of hairy. However, from what little
I have heard about Python, it's very well suited for readability due to
the whitespace requirements of the language, and very good for large
projects due to it's large amount of modules and it's object oriented
structure. I would like opinions as to the suitability of Python as a
general purpose language for programming unix, everything from short
scripts to muds. Thanks for your patience, opinions, and comments.

Xeys

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


Re: Python for everything?

2005-06-30 Thread Devan L
Python for everything except things that need to be ridiculously
optimized for speed. Thats what C embedded in Python and Psyco enhanced
Python code is for.

Oh wait, thats still all Python...

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


Re: Python for everything?

2005-06-30 Thread Larry Bates
Short answer is yes.

Longer answer: You will still need C for device drivers and other
applications that have high performance demands.  Calling C from
Python is quite easy.  Python can be used from short shell scripting
to projects that very large (see Zope, Plone, ReportLab, etc).  Other
than C, Python is the only language that I've been able to write
Windows Services (or *nix daemons), COM objects, GUI programs, text
programs, and headless programs (e.g. programs that produce no
console output).  I'm much more productive with Python.  By choosing
Python you commit to learning one language extremely well instead of
jumping all over with different languages that you can remember only
poorly.  When new version of Python ships, you just learn what is new.
If you try to keep up with C, C++, Visual Basic, ... it gets to be
impossible.

Hope information helps.

Larry Bates


[EMAIL PROTECTED] wrote:
 I posted a article earlier pertaining programming for my boss. Now I am
 gonna ask a question about programming for myself. I just finished my
 first C++ Class. Next semester is a class on encryption(and it's
 probably gonna be a math class too). And finally back in programming in
 the fall with C++ and Java 1. The C++ will cover pointers, and linked
 lists, sorting algorithms, etc... I run linux and OS X. I have read in
 the old days that C was used for everything. It was a systems
 programming language, and also did a lot of the same stuff Bash scripts
 and perl do now. So, in that era, C did it all, from short to tall. My
 question is, can Python do it all? I am wondering what to learn as my
 scripting language. I have read that perl is good up to about 250
 lines, and after that it gets kind of hairy. However, from what little
 I have heard about Python, it's very well suited for readability due to
 the whitespace requirements of the language, and very good for large
 projects due to it's large amount of modules and it's object oriented
 structure. I would like opinions as to the suitability of Python as a
 general purpose language for programming unix, everything from short
 scripts to muds. Thanks for your patience, opinions, and comments.
 
 Xeys
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-06-30 Thread Roy Smith
[EMAIL PROTECTED] wrote:
 I have read in the old days that C was used for everything. It was a
 systems programming language, and also did a lot of the same stuff
 Bash scripts and perl do now.

I learned C in the old days (1977 or maybe 78).  We had plenty of
other tools for scripting.  Before perl, we certainly had shell
scripts (although the early shells were not as powerful as
bash/ksh/etc), along with a healthy dose of utilities like
grep/sed/sort and awk.  I don't know anybody who tried to do
everything in C.

 My question is, can Python do it all?

Probably not.  I couldn't imagine writing an operating system in
Python; you'd never get the performance you need.  For very low-level
stuff that interfaces with hardware and twiddles with bits, it's
probably the wrong tool as well.

 I am wondering what to learn as my scripting language.

Python is an excellent scripting language, and I strongly urge you to
learn it.  But, for certain niches, there are better tools.  If you
main goal is to execute other processes and manipulate files, for
example, bash is probably a better tool.

Often, your choice of tool will be dictated by external constraints.
If you're trying to interface to some third-party system which only
has a perl or java API (not an uncommon situation), you're going to be
doing it in perl or java.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-06-30 Thread phil
Python is in my opinion the best all-purpose language ever
designed ( lisp is extremely cool but not as all purpose.)
Much more elegant than perl and far far easier to do cool things
than java (java is c++ on valium).

HOWEVER, all purpose needs a little disclosure.
A well coded C program may be 100 times faster than Python.
C forces you to learn some things about relative addressing
and memory management.
C is pretty much required for interrupt handling.
Python is coded in C. (everthing is coded in C, including C)
The C language embodies a language design philosophy which
has influenced everything for 30 years.

So Python is just a wonderful way to learn about things like
algorithms, with relatively little pain.  But the bottom
line for a would be computer scientist is that Python is
sort of like a model or an abstraction of C (which itself
is a very weak (but convenient)  model of the CPU)

IMHO

There probably is NO college where you can get out of
C++ and Java.  Too bad.

[EMAIL PROTECTED] wrote:

 I posted a article earlier pertaining programming for my boss. Now I am
 gonna ask a question about programming for myself. I just finished my
 first C++ Class. Next semester is a class on encryption(and it's
 probably gonna be a math class too). And finally back in programming in
 the fall with C++ and Java 1. The C++ will cover pointers, and linked
 lists, sorting algorithms, etc... I run linux and OS X. I have read in
 the old days that C was used for everything. It was a systems
 programming language, and also did a lot of the same stuff Bash scripts
 and perl do now. So, in that era, C did it all, from short to tall. My
 question is, can Python do it all? I am wondering what to learn as my
 scripting language. I have read that perl is good up to about 250
 lines, and after that it gets kind of hairy. However, from what little
 I have heard about Python, it's very well suited for readability due to
 the whitespace requirements of the language, and very good for large
 projects due to it's large amount of modules and it's object oriented
 structure. I would like opinions as to the suitability of Python as a
 general purpose language for programming unix, everything from short
 scripts to muds. Thanks for your patience, opinions, and comments.
 
 Xeys
 
 



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


Re: Python for everything?

2005-06-30 Thread Mike Meyer
[EMAIL PROTECTED] writes:

 I posted a article earlier pertaining programming for my boss. Now I am
 gonna ask a question about programming for myself. I just finished my
 first C++ Class. Next semester is a class on encryption(and it's
 probably gonna be a math class too). And finally back in programming in
 the fall with C++ and Java 1. The C++ will cover pointers, and linked
 lists, sorting algorithms, etc... I run linux and OS X. I have read in
 the old days that C was used for everything. It was a systems
 programming language, and also did a lot of the same stuff Bash scripts
 and perl do now. So, in that era, C did it all, from short to tall. My
 question is, can Python do it all? I am wondering what to learn as my
 scripting language. I have read that perl is good up to about 250
 lines, and after that it gets kind of hairy. However, from what little
 I have heard about Python, it's very well suited for readability due to
 the whitespace requirements of the language, and very good for large
 projects due to it's large amount of modules and it's object oriented
 structure. I would like opinions as to the suitability of Python as a
 general purpose language for programming unix, everything from short
 scripts to muds. Thanks for your patience, opinions, and comments.

As other have noted, C was never really used for everything. Unix
tools were designed to connect together from the very beginning, which
is what makes shell scripting so powerful. This was true before there
was a C. Likewise, some things you need more control over the machine
than you get in C - those are still done in assembler. These days, C
compilers let you embed assembler statements in your C, so some of
these things are done in such variants.

Some things require you to be able to generate machine code. Those
can't be done in any current implementation of Python. That doesn't
mean they'll never be doable in Python - just not now. As mentioned,
some things needvery explicit control over the generated machine
code. Those things aren't done in C now, and will never be done in C
or Python.

Rather than talk about how suitable Python is for programming in
general, I wanted to talk about the things you mentioned you'd be
learning.

Python doesn't have explicit pointers - except that every name is a
pointer. That makes it hard to learn about pointers with Python. You
can do data structures in Python, though. Just replace the C/C++
struct with a class, and manipulate the attributes like you'd
manipulate struct members. For instance, a linked list might be
represented by:

class ListNode:
def __init__(self, data):
self.data = data
self.next = None

A routine that manipulated a list might look like:

   def cons(car, cdr): car.next = cdr

Though I'd be tempted to make it a method of ListNode:

   def cons(self, cdr): self.next = cdr

You build a list from the back to the front like so:

LinkedList = cons(ListNode(1), cons(ListNode(2), ListNode(3)))

or

LinkedList = ListNode(1).cons(ListNode(2).cons(ListNode(3)))

(this is heavily influenced by LISP; you might prever a different
abstraction) and then you'd iterate over the list like so:

 item = LinkedList
 while item:
 Process(item.data)
 item = item.next

Compared to a C implementation, which would look like:

 struct ListNode {
 struct ListNode *next ;
 void *data ;
 } ;

and an iteration like so:

struct ListNode *item ;
item = LinkedList ;
while (item) {
  Process(item-data) ;
  item = item-next ;
}

I won't get into the details of building a list in C. It's just too
ugly.

Sorting is generally done on arrays, though there are methods that use
lists, etc. You can study those just fine in Python. However, those
are mostly of academic interest. Any computing platform worth
mentioning will have a good, general-purpose sort facility
available. Using that is certainly faster than writing and debugging
your own.

 mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-06-30 Thread Ivan Van Laningham
Hi All--

Mike Meyer wrote:
 
 [EMAIL PROTECTED] writes:
 
 As other have noted, C was never really used for everything. Unix
 tools were designed to connect together from the very beginning, which
 is what makes shell scripting so powerful. This was true before there
 was a C. Likewise, some things you need more control over the machine
 than you get in C - those are still done in assembler. These days, C
 compilers let you embed assembler statements in your C, so some of
 these things are done in such variants.
 

It really was used for everything; C compilers have *always* let you
include assembler, with the asm keyword.  Unless you're talking about
the early days of DOS/Windows compilers, about which I know little, but
all *KR* compilers had asm.  If you wanted to write kernel code and
device driver code (including disk drivers) for large Unix systems, asm
was a requirement.  To put it in perspective, for Gould systems in the
80s, for the entire OS (BSD-derived Unix), there were under 100 lines of
assembler, all in a very few device drivers (multiple thousands of lines
of code, don't remember exactly how many).

And living with structs instead of classes was not nearly as much of a
pain in the butt as you make out; it was perfectly reasonable to include
methods within structs, by including a pointer to a function.  X10 and
X11 showed just how object-oriented you could get with C, using
callbacks with required signatures, and specifying how Widgets were to
be written--contracts before there were contracts.

It's true that OO languages are better, and languages like Python which
allow you to combine fairly low-level calls with an OO worldview make
life *vastly* easier, but C is still hugely flexible, highly adaptable,
and very powerful.  For about 10 or 15 years there, knowing C was pretty
much a guarantee of a good job.  That changed when C++ compilers became
common and good and not merely preprocessors that wrote really, really
ugly C.

Metta,
while(*s++=*p++);-ly y'rs,
Ivan;-)
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-06-30 Thread Mike Meyer
Ivan Van Laningham [EMAIL PROTECTED] writes:
 Mike Meyer wrote:
 [EMAIL PROTECTED] writes:
 As other have noted, C was never really used for everything. Unix
 tools were designed to connect together from the very beginning, which
 is what makes shell scripting so powerful. This was true before there
 was a C. Likewise, some things you need more control over the machine
 than you get in C - those are still done in assembler. These days, C
 compilers let you embed assembler statements in your C, so some of
 these things are done in such variants.
 It really was used for everything; C compilers have *always* let you
 include assembler, with the asm keyword.  Unless you're talking about
 the early days of DOS/Windows compilers, about which I know little, but
 all *KR* compilers had asm.

Actually, I was thinking of pre-KR Unix compilers. The v6 Unix
compiler, and the photo7 compiler. I don't believe they had asm
statements. If they did, it wasn't used in the v6 kernel.

 And living with structs instead of classes was not nearly as much of a
 pain in the butt as you make out; it was perfectly reasonable to include
 methods within structs, by including a pointer to a function.  X10 and
 X11 showed just how object-oriented you could get with C, using
 callbacks with required signatures, and specifying how Widgets were to
 be written--contracts before there were contracts.

Yeah, X is a good example of how to do OO programming in a non-OO
language. The current BSD kernels do the same kind of things.  But I'd
say it was a bigger pain in the but than I made out to be. You wind up
having to invoke the function through your data object, and then pass
the data object in - sort of as an explicit self.

 It's true that OO languages are better, and languages like Python which
 allow you to combine fairly low-level calls with an OO worldview make
 life *vastly* easier, but C is still hugely flexible, highly adaptable,
 and very powerful.  For about 10 or 15 years there, knowing C was pretty
 much a guarantee of a good job.  That changed when C++ compilers became
 common and good and not merely preprocessors that wrote really, really
 ugly C.

I still use C when I need more control/speed than I can get out of
Python (or something modern). And for wrapping things to use in
HLLs.

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list