New to Python; what about #include, extern and function prototypes

Discussion in 'Python' started by Bo Jacobsen, Mar 7, 2004.

  1. Bo Jacobsen

    Bo Jacobsen Guest

    I'm new to Python, and it looks as if there is no
    C like "#include and extern" or function protypes. No shell like ".
    .../filename"
    is this correct ?.

    Is there any way to implement them ?

    PS: For me, "import module" is no replacement for include.



    Bo Jacobsen
     
    Bo Jacobsen, Mar 7, 2004
    #1
    1. Advertising

  2. In article <Fkx2c.105588$> (Sun, 07 Mar
    2004 05:14:20 +0100), Bo Jacobsen wrote:

    > I'm new to Python, and it looks as if there is no
    > C like "#include and extern" or function protypes.


    That's right.

    > No shell like ".
    > ../filename"


    I don't understand this part.

    > Is there any way to implement them ?


    I don't know. I've been a C programmer for almost exactly 20 years: Neither
    "extern" nor function prototypes are necessary in Python.

    > PS: For me, "import module" is no replacement for include.


    "import" and "#include" do not have exactly the same meaning but they
    accomplish more or less the same result.

    What is it you're trying to do that requires these C/C++ features?
     
    Hamilcar Barca, Mar 7, 2004
    #2
    1. Advertising

  3. Bo Jacobsen

    Bo Jacobsen Guest

    > In article <Fkx2c.105588$> (Sun, 07 Mar
    > 2004 05:14:20 +0100), Bo Jacobsen wrote:
    >
    > > I'm new to Python, and it looks as if there is no
    > > C like "#include and extern" or function protypes.

    >
    > That's right.
    >
    > > No shell like ".
    > > ../filename"

    >
    > I don't understand this part.
    >
    > > Is there any way to implement them ?

    >
    > I don't know. I've been a C programmer for almost exactly 20 years:

    Neither
    > "extern" nor function prototypes are necessary in Python.
    >
    > > PS: For me, "import module" is no replacement for include.

    >
    > "import" and "#include" do not have exactly the same meaning but they
    > accomplish more or less the same result.
    >
    > What is it you're trying to do that requires these C/C++ features?


    I'm looking for a future replacement for bash and I have a number of large
    shell scripts that need to be translated to a language that are better at
    handling
    more complicated datatypes.
    I'm been looking at perl and python, and I really like the strict syntax,
    handling
    of function parameters etc. Without include and function prototyping though,
    will probably have the effect that large source files, with a lot of
    function
    definitions at the top, will be generated. Not god.

    Perl on the other hand has it all, including very productive features as
    built-in
    regular expressions, file scanning etc. but I dont like all the
    type-characters and
    the "lose" syntax.


    .. ./filename
    Is the shell "include/execute" command.

    Bo
     
    Bo Jacobsen, Mar 7, 2004
    #3
  4. Bo Jacobsen wrote:

    > I'm been looking at perl and python, and I really like the strict syntax,
    > handling
    > of function parameters etc. Without include and function prototyping though,
    > will probably have the effect that large source files, with a lot of
    > function
    > definitions at the top, will be generated. Not god.


    Why do you think this is so?

    Have a look at any Python example sourcecode (for that matter,
    at some of the .py files from Python's standard library; for instance
    cgi.py) and you will see that Python's import mechanism is working fine.
    No big source files with lots of definitions at the top.
    Just import the module which contains the definitions you need...


    > Perl on the other hand has it all, including very productive features as
    > built-in
    > regular expressions, file scanning etc.


    Python has the re/sre module for regular expression stuff.
    File scanning is often done like this:
    for line in open("myfile.txt"):
    process(line)

    > . ./filename
    > Is the shell "include/execute" command.


    Python's "include" command is the import statement.
    If you really want (but WHY?) to read in and directly
    execute another source file, use the execfile function.

    --Irmen
     
    Irmen de Jong, Mar 7, 2004
    #4
  5. Bo Jacobsen

    Bo Jacobsen Guest

    > > I'm been looking at perl and python, and I really like the strict
    syntax,
    > > handling
    > > of function parameters etc. Without include and function prototyping

    though,
    > > will probably have the effect that large source files, with a lot of
    > > function
    > > definitions at the top, will be generated. Not god.

    >
    > Why do you think this is so?
    >
    > Have a look at any Python example sourcecode (for that matter,
    > at some of the .py files from Python's standard library; for instance
    > cgi.py) and you will see that Python's import mechanism is working fine.
    > No big source files with lots of definitions at the top.
    > Just import the module which contains the definitions you need...
    >
    >
    > > Perl on the other hand has it all, including very productive features as
    > > built-in
    > > regular expressions, file scanning etc.

    >
    > Python has the re/sre module for regular expression stuff.
    > File scanning is often done like this:
    > for line in open("myfile.txt"):
    > process(line)
    >
    > > . ./filename
    > > Is the shell "include/execute" command.

    >
    > Python's "include" command is the import statement.
    > If you really want (but WHY?) to read in and directly
    > execute another source file, use the execfile function.
    >
    > --Irmen


    I'm very new to Phyton (I looked at it for the first time last night), so
    you must have me excused.
    The "execfile" perfectly solves my worries about prototyping and
    include, GREAT.
    As I wrote earlier, I really like the "feeling" of the language, now I
    just have to find the time to dig more into it.

    By the way, is there an elegant way to read shell program output
    into a variable as in bash: var=$(command1 | command2)


    Bo
     
    Bo Jacobsen, Mar 7, 2004
    #5
  6. Bo Jacobsen

    Uwe Grauer Guest

    Bo,

    to read shell program output use:
    os.popen()

    Uwe

    Bo Jacobsen wrote:
    >>>I'm been looking at perl and python, and I really like the strict

    >
    > syntax,
    >
    >>>handling
    >>>of function parameters etc. Without include and function prototyping

    >
    > though,
    >
    >>>will probably have the effect that large source files, with a lot of
    >>>function
    >>>definitions at the top, will be generated. Not god.

    >>
    >>Why do you think this is so?
    >>
    >>Have a look at any Python example sourcecode (for that matter,
    >>at some of the .py files from Python's standard library; for instance
    >>cgi.py) and you will see that Python's import mechanism is working fine.
    >>No big source files with lots of definitions at the top.
    >>Just import the module which contains the definitions you need...
    >>
    >>
    >>
    >>>Perl on the other hand has it all, including very productive features as
    >>>built-in
    >>>regular expressions, file scanning etc.

    >>
    >>Python has the re/sre module for regular expression stuff.
    >>File scanning is often done like this:
    >>for line in open("myfile.txt"):
    >>process(line)
    >>
    >>
    >>>. ./filename
    >>>Is the shell "include/execute" command.

    >>
    >>Python's "include" command is the import statement.
    >>If you really want (but WHY?) to read in and directly
    >>execute another source file, use the execfile function.
    >>
    >>--Irmen

    >
    >
    > I'm very new to Phyton (I looked at it for the first time last night), so
    > you must have me excused.
    > The "execfile" perfectly solves my worries about prototyping and
    > include, GREAT.
    > As I wrote earlier, I really like the "feeling" of the language, now I
    > just have to find the time to dig more into it.
    >
    > By the way, is there an elegant way to read shell program output
    > into a variable as in bash: var=$(command1 | command2)
    >
    >
    > Bo
    >
    >
    >
     
    Uwe Grauer, Mar 7, 2004
    #6
  7. In article <RGF2c.105804$>, Bo Jacobsen
    wrote:

    > By the way, is there an elegant way to read shell program output
    > into a variable as in bash: var=$(command1 | command2)


    I usually use the commands module:

    import commands

    status, output = commands.getstatusoutput("command1 | command2")

    status would be $? in bashese.

    Dave Cook
     
    David M. Cook, Mar 7, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Matthews
    Replies:
    5
    Views:
    2,440
    tom_usenet
    Aug 2, 2004
  2. Kristian Virkus
    Replies:
    7
    Views:
    410
    Thad Smith
    Feb 8, 2007
  3. quarkLore

    extern and function prototypes

    quarkLore, Apr 19, 2007, in forum: C Programming
    Replies:
    5
    Views:
    311
  4. Syren Baran

    function prototypes and function addresses

    Syren Baran, Jan 9, 2008, in forum: C Programming
    Replies:
    6
    Views:
    309
  5. Andre
    Replies:
    5
    Views:
    542
    Keith Thompson
    Jul 17, 2012
Loading...

Share This Page