Python

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • (no subject)

    17 answers - 227 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    hello is there a way if a condition is not met to restart the whole program?
    for example if and if statement returns true then re start the whole
    program?
    Tutor maillist - Tutor (AT) python (DOT) org
  • No.1 | | 401 bytes | |

    hello is there a way if a condition is not met to restart the whole
    program? for example if and if statement returns true then re start the
    whole program?

    Question before we go on: why are you trying to do this?

    It's possible to do this, but it sounds so unusual that I want to know
    more about the problem.

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.2 | | 816 bytes | |

    Amadeo Bellotti wrote:
    hello is there a way if a condition is not met to restart the whole
    program? for example if and if statement returns true then re start
    the whole program?

    You can probably achieve what you want just by structuring the program
    correctly. My guess you need to use nested loops, something like this:

    while True:
    initialize_everything()
    while True:
    if something_is_wrong():
    break
    do_some_work()

    This will do_some_work() until something_is_wrong(), then it will
    initialize_everything() and try again.

    If the test for something_is_wrong() is buried deep in the code you can
    break the loop by raising an exception which you catch in the top-level
    loop.

    Kent

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.3 | | 1853 bytes | |

    Amadeo Bellotti wrote:
    Mr. Johnson i was hoping i didnt have to make my whole program into a
    loop because its about 900 lines of code and tabbing that would take a
    long time
    If your whole program is 900 lines without a subroutine then you have
    more problems than just tabbingreally, a program this big should have
    many functions to divide up the work. Looking for a workaround for poor
    program structure is not a good solution in the long run; fixing the
    program structure so it is workable is a better idea.

    As a practical matter, many editors allow you to select and indent a
    block, including TextPad and Eclipse, the two editors I usually use.

    Kent

    PS please reply to the list, not to me personally.
    >
    >
    >

    8/17/06, *Kent Johnson* <kent37 (AT) tds (DOT) net <mailto:kent37 (AT) tds (DOT) net>
    wrote:

    Amadeo Bellotti wrote:
    hello is there a way if a condition is not met to restart the whole
    program? for example if and if statement returns true then re start
    the whole program?

    You can probably achieve what you want just by structuring the
    program
    correctly. My guess you need to use nested loops, something like this:

    while True:
    initialize_everything()
    while True:
    if something_is_wrong():
    break
    do_some_work()

    This will do_some_work() until something_is_wrong(), then it will
    initialize_everything() and try again.

    If the test for something_is_wrong() is buried deep in the code
    you can
    break the loop by raising an exception which you catch in the
    top-level
    loop.

    Kent

    Tutor maillist - Tutor (AT) python (DOT) org <mailto:Tutor (AT) python (DOT) org>

    <>
    --

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.4 | | 2192 bytes | |

    thank you Mr. Johnson this is my first program so its a little sloppy. I'm
    using gedit ill check out the other editors that u have thank you

    8/17/06, Kent Johnson <kent37 (AT) tds (DOT) netwrote:

    Amadeo Bellotti wrote:
    Mr. Johnson i was hoping i didnt have to make my whole program into a
    loop because its about 900 lines of code and tabbing that would take a
    long time
    If your whole program is 900 lines without a subroutine then you have
    more problems than just tabbingreally, a program this big should have
    many functions to divide up the work. Looking for a workaround for poor
    program structure is not a good solution in the long run; fixing the
    program structure so it is workable is a better idea.

    As a practical matter, many editors allow you to select and indent a
    block, including TextPad and Eclipse, the two editors I usually use.

    Kent

    PS please reply to the list, not to me personally.
    >
    >
    >

    8/17/06, *Kent Johnson* <kent37 (AT) tds (DOT) net <mailto:kent37 (AT) tds (DOT) net>>
    wrote:

    Amadeo Bellotti wrote:
    hello is there a way if a condition is not met to restart the
    whole
    program? for example if and if statement returns true then re
    start
    the whole program?

    You can probably achieve what you want just by structuring the
    program
    correctly. My guess you need to use nested loops, something like
    this:

    while True:
    initialize_everything()
    while True:
    if something_is_wrong():
    break
    do_some_work()

    This will do_some_work() until something_is_wrong(), then it will
    initialize_everything() and try again.

    If the test for something_is_wrong() is buried deep in the code
    you can
    break the loop by raising an exception which you catch in the
    top-level
    loop.

    Kent

    Tutor maillist - Tutor (AT) python (DOT) org <mailto:Tutor (AT) python (DOT) org>

    <>
    >
    >
    >
    >


    Tutor maillist - Tutor (AT) python (DOT) org

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.5 | | 494 bytes | |

    thank you Mr. Johnson this is my first program so its a little sloppy. I'm
    using gedit ill check out the other editors that u have thank you

    More fundamentally, spend some time to learn about functions; they'll
    address much of the original concerns you had. See any of the tutorials
    on:

    and almost all of them should talk about what functions are, and how to
    use them.

    Best of wishes!

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.6 | | 651 bytes | |

    Thank you again i no im a newbie and really inexperianced but thank you

    8/17/06, Danny Yoo <dyoo (AT) hkn (DOT) eecs.berkeley.eduwrote:

    thank you Mr. Johnson this is my first program so its a little sloppy.
    I'm
    using gedit ill check out the other editors that u have thank you

    More fundamentally, spend some time to learn about functions; they'll
    address much of the original concerns you had. See any of the tutorials
    on:

    and almost all of them should talk about what functions are, and how to
    use them.

    Best of wishes!

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.7 | | 1236 bytes | |

    thank you Mr. Johnson this is my first program so its a little
    sloppy. I'm
    using gedit ill check out the other editors that u have thank you

    If you have Python you will have either IDLE or Pythonwin (or both)
    Both of these will allow block indent/unindent so simply load the
    code into IDLE to do the indentation You can go back to gedit
    afterwards if you like.

    But as Kent said you should ideally aimto write the code as
    functions, each about 5-50 lines long (less than 5 and the advantage
    is minimal, mor than 50 is just too long - around 12 lines per
    functoion
    is a good average IMH

    But don't use number of lines as the deciding factor! Divide the code
    into blocks of code that do something logical that you can describe
    in a few words (see the comments from Danny to Kermit for examples!)
    Use those few words to name the function. Consider how to pass key
    data between the funbctions using parameters and return values.

    If you don't know how to write functions take a look at the Functions
    topic of my tutor.

    HTH,

    Alan Gauld
    Author of the Learn to Program web site

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.8 | | 1410 bytes | |

    thank you but IDLE doesnt seem to work on Suse 9.2 do you know a way to fix
    it?

    8/17/06, Alan Gauld <alan.gauld (AT) freenet (DOT) co.ukwrote:

    thank you Mr. Johnson this is my first program so its a little
    sloppy. I'm
    using gedit ill check out the other editors that u have thank you

    If you have Python you will have either IDLE or Pythonwin (or both)
    Both of these will allow block indent/unindent so simply load the
    code into IDLE to do the indentation You can go back to gedit
    afterwards if you like.

    But as Kent said you should ideally aimto write the code as
    functions, each about 5-50 lines long (less than 5 and the advantage
    is minimal, mor than 50 is just too long - around 12 lines per
    functoion
    is a good average IMH

    But don't use number of lines as the deciding factor! Divide the code
    into blocks of code that do something logical that you can describe
    in a few words (see the comments from Danny to Kermit for examples!)
    Use those few words to name the function. Consider how to pass key
    data between the funbctions using parameters and return values.

    If you don't know how to write functions take a look at the Functions
    topic of my tutor.

    HTH,

    Alan Gauld
    Author of the Learn to Program web site

    --

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.9 | | 221 bytes | |

    18/08/06, Amadeo Bellotti <amadeo.bellotti (AT) gmail (DOT) comwrote:
    thank you but IDLE doesnt seem to work on Suse 9.2 do you know a way to fix
    it?
    Why not -- what goes wrong? Is there an error message?
  • No.10 | | 942 bytes | |

    Thu, Aug 17, 2006 at 01:28:56PM -0400, Amadeo Bellotti wrote:
    thank you Mr. Johnson this is my first program so its a little sloppy. I'm
    using gedit ill check out the other editors that u have thank you

    I'd also encourage you to look at other editors, as others on this
    list have.

    However, if you like and want to stay with gedit, try to do the
    following (if you have not already) -- Click on menu item
    Edit/Preferences, then click on the Plugins tab and enable
    "Indent lines" plugin. After doing so, there should be Indent and
    Unindent items in the Edit menu. Highlight a block of code, and
    try those operations.

    Indent and Unindent operations will enable you to easily convert top
    level code into a function: specifically, Indent block and add a
    "def" statement at the top.

    I apologize if the above is overly simple-minded and if you are
    already past this.

    Dave
  • No.11 | | 415 bytes | |

    Mr. Kuhlman it says python is not configured for tk.

    but on another note does anyone know how to make a 2d array?

    8/18/06, John Fouhy <john (AT) fouhy (DOT) netwrote:

    18/08/06, Amadeo Bellotti <amadeo.bellotti (AT) gmail (DOT) comwrote:
    thank you but IDLE doesnt seem to work on Suse 9.2 do you know a way to
    fix
    it?

    Why not -- what goes wrong? Is there an error message?
  • No.12 | | 418 bytes | |

    18/08/06, Amadeo Bellotti <amadeo.bellotti (AT) gmail (DOT) comwrote:
    Mr. Kuhlman it says python is not configured for tk.

    but on another note does anyone know how to make a 2d array?

    Are you in charge of your machine, or does someone else administer it?

    I don't know SUSE very well, but I expect that you can fix this by
    installing a package called something like "python-tkinter".
  • No.13 | | 455 bytes | |

    thank you but IDLE doesnt seem to work on Suse 9.2 do you know a way
    to fix
    it?

    I've only used IDLE on Linux a few times but it certainly works
    on RedHat, Mandriva and Slackware. And it used to work on
    Suse 5 - the only time I ever used Suse

    What hapens when you try to run IDLE? It may just be a case of
    fixing a path setting or somesuch.

    Alan G.

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.14 | | 1792 bytes | |

    Mr. Kuhlman it says python is not configured for tk.

    Gaarrgh! Why do linux distros do this? Stooopid

    You will need to fetch another version of Python with
    Tk support built in. Its a compile time option so you can
    either fetch the source an build it yourself or find a Suse
    package with Tk support already selected.

    Its really stupid for Suse to do that, it only saves a tiny
    amount of space and means you can't run any programs
    based on Tkinter

    but on another note does anyone know how to make a 2d array?

    This should probably be a separate post.

    Also can you change the subject line in your posts so people
    can fiind the thread easily. I've changed it on this one to pick
    up the 2D array issue

    A 2D array is just a table. There are several ways to do that
    in Python but the easiest is just a list of lists: Think of a chess
    game as an example where the boars is represented by
    an 8x8 2D array:

    chessBoard = [
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0]
    ]

    Now you can access the third row, 4th column with:

    chessBoard[2][3] # remember zero indexing!

    Is that clear?

    You can also use tuples similarly, or nested dictionaries.
    A lot will depend on the data you are storing and how you
    want to access it.

    Finally you can create a Class with bespoke methods to
    more closely model your problem, but the class will usaually
    have one of the above solutions internally anyhow!

    HTH.

    Alan Gauld
    Author of the Learn to Program web site

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.15 | | 421 bytes | |

    Alan Gauld wrote:
    >but on another note does anyone know how to make a 2d array?
    >
    >

    A 2D array is just a table. There are several ways to do that
    in Python
    <snip several good suggestions>

    If you need high-performance arrays you should look at numpy:
    http://numpy.scipy.org/

    Kent

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.16 | | 1912 bytes | |

    thank you so much Mr. Gauld that really helped

    8/18/06, Alan Gauld <alan.gauld (AT) freenet (DOT) co.ukwrote:

    Mr. Kuhlman it says python is not configured for tk.

    Gaarrgh! Why do linux distros do this? Stooopid

    You will need to fetch another version of Python with
    Tk support built in. Its a compile time option so you can
    either fetch the source an build it yourself or find a Suse
    package with Tk support already selected.

    Its really stupid for Suse to do that, it only saves a tiny
    amount of space and means you can't run any programs
    based on Tkinter

    but on another note does anyone know how to make a 2d array?

    This should probably be a separate post.

    Also can you change the subject line in your posts so people
    can fiind the thread easily. I've changed it on this one to pick
    up the 2D array issue

    A 2D array is just a table. There are several ways to do that
    in Python but the easiest is just a list of lists: Think of a chess
    game as an example where the boars is represented by
    an 8x8 2D array:

    chessBoard = [
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0],
    [0,0,0,0,0,0,0,0]
    ]

    Now you can access the third row, 4th column with:

    chessBoard[2][3] # remember zero indexing!

    Is that clear?

    You can also use tuples similarly, or nested dictionaries.
    A lot will depend on the data you are storing and how you
    want to access it.

    Finally you can create a Class with bespoke methods to
    more closely model your problem, but the class will usaually
    have one of the above solutions internally anyhow!

    HTH.

    Alan Gauld
    Author of the Learn to Program web site

    Tutor maillist - Tutor (AT) python (DOT) org
  • No.17 | | 808 bytes | |

    Mr. Gauld I run it from termainal on GNME and it says "** IDLE can't import
    Tkinter. Your Python may not be configured for Tk. **"

    and Yea I am Administrator this is my Home computer after all im only 15.

    8/18/06, Alan Gauld <alan.gauld (AT) freenet (DOT) co.ukwrote:
    --
    thank you but IDLE doesnt seem to work on Suse 9.2 do you know a way
    to fix
    it?

    I've only used IDLE on Linux a few times but it certainly works
    on RedHat, Mandriva and Slackware. And it used to work on
    Suse 5 - the only time I ever used Suse

    What hapens when you try to run IDLE? It may just be a case of
    fixing a path setting or somesuch.

    Alan G.
    >
    >
    >


    Tutor maillist - Tutor (AT) python (DOT) org

Re: (no subject)


max 4000 letters.
Your nickname that display:
In order to stop the spam: 5 + 4 =
QUESTION ON "Python"

EMSDN.COM