Parameter Passing - String Variable Truncated ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • goldtech

    Parameter Passing - String Variable Truncated ?

    Hi,

    I'm passing what I think is a string parameter to another Python
    program (spawn.py) - see the code snip below. But only the counter
    part gets printed to a log file via spawn.py. Yet the echo print to
    the output window shows the whole string with the fc part. Better
    explained below I hope, there's the calling .py and the spawn
    script .py:
    ....snip...
    while fc:
    counter = counter + 1
    fc_cntr = str(counter) + ' : ' + fc
    print fc_cntr + '\n' # Print to Pythonwin interactive window -
    eg. "1 : New York" - all is printed OK

    arglist = []
    arglist.append( pythonPath)
    arglist.append( spawn_script)
    arglist.append( fc_cntr) # This gets sent to the spawn_script but
    only "1" gets printed

    os.spawnv(os.P_ WAIT, pythonPath, arglist)
    fc = fcs.next()
    ....
    --------------------------
    ## the spawn_script
    import win32com.client , sys, os, time, re

    in_featclass = sys.argv[1]
    handle = open('C:\\log_f ile.txt', 'a')
    handle.write(in _featclass + "\n") # ONLY the counter part gets printed
    to the log file! Why?
    --------------------------

    Thanks, for help.

  • John Machin

    #2
    Re: Parameter Passing - String Variable Truncated ?

    On Sep 1, 9:54 am, goldtech <goldt...@world post.comwrote:
    Hi,
    >
    I'm passing what I think is a string parameter to another Python
    program (spawn.py) - see the code snip below. But only the counter
    part gets printed to a log file via spawn.py. Yet the echo print to
    the output window shows the whole string with the fc part. Better
    explained below I hope, there's the calling .py and the spawn
    script .py:
    ...snip...
    while fc:
    counter = counter + 1
    fc_cntr = str(counter) + ' : ' + fc
    print fc_cntr + '\n' # Print to Pythonwin interactive window -
    eg. "1 : New York" - all is printed OK
    >
    arglist = []
    arglist.append( pythonPath)
    arglist.append( spawn_script)
    arglist.append( fc_cntr) # This gets sent to the spawn_script but
    only "1" gets printed
    >
    os.spawnv(os.P_ WAIT, pythonPath, arglist)
    fc = fcs.next()
    ...
    --------------------------
    ## the spawn_script
    import win32com.client , sys, os, time, re
    >
    in_featclass = sys.argv[1]
    handle = open('C:\\log_f ile.txt', 'a')
    handle.write(in _featclass + "\n") # ONLY the counter part gets printed
    to the log file! Why?
    --------------------------
    Try handle.write(re pr(sys.argv[1:]) + "\n")
    and come back with your conclusions ... unless of course someone has
    spoonfed you in the meantime.

    Another clue: write yourself a little arg-dumper script and try
    running it in a Command Prompt window.
    8<---
    import sys
    for x, arg in enumerate(sys.a rgv):
    print x, repr(arg)
    8<---
    HTH,
    John

    Comment

    • Steve Holden

      #3
      Re: Parameter Passing - String Variable Truncated ?

      goldtech wrote:
      Hi,
      >
      I'm passing what I think is a string parameter to another Python
      program (spawn.py) - see the code snip below. But only the counter
      part gets printed to a log file via spawn.py. Yet the echo print to
      the output window shows the whole string with the fc part. Better
      explained below I hope, there's the calling .py and the spawn
      script .py:
      ...snip...
      while fc:
      counter = counter + 1
      fc_cntr = str(counter) + ' : ' + fc
      print fc_cntr + '\n' # Print to Pythonwin interactive window -
      eg. "1 : New York" - all is printed OK
      >
      arglist = []
      arglist.append( pythonPath)
      arglist.append( spawn_script)
      arglist.append( fc_cntr) # This gets sent to the spawn_script but
      only "1" gets printed
      >
      os.spawnv(os.P_ WAIT, pythonPath, arglist)
      fc = fcs.next()
      ...
      --------------------------
      ## the spawn_script
      import win32com.client , sys, os, time, re
      >
      in_featclass = sys.argv[1]
      Try

      in_featclass = sys.argv[1:]

      to collect all the arguments. At the moment I suspect some shell
      argument processing is intervening, splitting your "N : something" into
      multiple arguments.
      handle = open('C:\\log_f ile.txt', 'a')
      handle.write(in _featclass + "\n") # ONLY the counter part gets printed
      to the log file! Why?
      --------------------------
      >
      Thanks, for help.
      >
      regards
      Steve
      --
      Steve Holden +1 571 484 6266 +1 800 494 3119
      Holden Web LLC/Ltd http://www.holdenweb.com
      Skype: holdenweb http://del.icio.us/steve.holden
      --------------- Asciimercial ------------------
      Get on the web: Blog, lens and tag the Internet
      Many services currently offer free registration
      ----------- Thank You for Reading -------------

      Comment

      • Steve Holden

        #4
        Re: Parameter Passing - String Variable Truncated ?

        Steve Holden wrote:
        [...]
        >in_featclass = sys.argv[1]
        >
        Try
        >
        in_featclass = sys.argv[1:]
        >
        Sorry, that should have been

        in_featclass = " ".join(sys. argv[1:])+"\n"

        regards
        Steve
        --
        Steve Holden +1 571 484 6266 +1 800 494 3119
        Holden Web LLC/Ltd http://www.holdenweb.com
        Skype: holdenweb http://del.icio.us/steve.holden
        --------------- Asciimercial ------------------
        Get on the web: Blog, lens and tag the Internet
        Many services currently offer free registration
        ----------- Thank You for Reading -------------

        Comment

        • Steve Holden

          #5
          Re: Parameter Passing - String Variable Truncated ?

          Steve Holden wrote:
          [...]
          >in_featclass = sys.argv[1]
          >
          Try
          >
          in_featclass = sys.argv[1:]
          >
          Sorry, that should have been

          in_featclass = " ".join(sys. argv[1:])+"\n"

          regards
          Steve
          --
          Steve Holden +1 571 484 6266 +1 800 494 3119
          Holden Web LLC/Ltd http://www.holdenweb.com
          Skype: holdenweb http://del.icio.us/steve.holden
          --------------- Asciimercial ------------------
          Get on the web: Blog, lens and tag the Internet
          Many services currently offer free registration
          ----------- Thank You for Reading -------------

          Comment

          • goldtech

            #6
            Re: Parameter Passing - String Variable Truncated ?

            snip...
            --------------------------
            >
            Try handle.write(re pr(sys.argv[1:]) + "\n")
            and come back with your conclusions ... unless of course someone has
            spoonfed you in the meantime.
            >
            Another clue: write yourself a little arg-dumper script and try
            running it in a Command Prompt window.
            8<---
            import sys
            for x, arg in enumerate(sys.a rgv):
            print x, repr(arg)
            8<---
            HTH,
            John
            It's a list.

            ....
            ['5', ':', 'Alaska.shp']
            ['6', ':', 'Arizona.shp']
            ['7', ':', 'Arkansas.shp']
            ['8', ':', 'California.shp ']
            ['9', ':', 'Colorado.shp']
            ['10', ':', 'Connecticut.sh p']
            ['11', ':', 'Delaware.shp']
            ['12', ':', 'District', 'of', 'Columbia.shp']
            ['13', ':', 'Florida.shp']
            ['14', ':', 'West', 'Virginia.shp']
            ['15', ':', 'Wisconsin.shp']
            ['16', ':', 'Wyoming.shp']

            Thanks,
            Lee G.

            Comment

            Working...