User Profile

Collapse

Profile Sidebar

Collapse
nihilium
nihilium
Last Activity: Apr 28 '12, 08:44 PM
Joined: Mar 8 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • That works if declare all the variables to be global. The file in question is a configuration file for a much larger framework that I do not want to edit, as that would probably create troubles when updating it.

    It is pretty ugly having to declare each variable as global (otherwise, the framework crashes), and also initiating the function. I mean, this is what the code ends up like

    Code:
    var = 1
    
    def
    ...
    See more | Go to post

    Leave a comment:


  • nihilium
    started a topic Leaving a .py file before all code is executed

    Leaving a .py file before all code is executed

    I am looking for something that is a crossbreed between exit() and return. Let's say I am importing the file below:

    Code:
    if variable:
        print 'returning to main program'
        # stop executing more code in this file
        # and return to the main program
    else:
        pass
    # more code goes here
    print 'the rest of the code was executed'
    See more | Go to post
    Last edited by nihilium; Apr 21 '12, 05:52 PM. Reason: sp.

  • Right, that works. :-D

    It wouldn't "support" copy and paste through right click, but I am not sure if I am going to implement that anyway (and I guess <<modified>> would support it).

    So I'll consider the case solved for the time being. Thanks for the input.
    See more | Go to post

    Leave a comment:


  • By the gods, I have been reading the articles on effbot since I started creating my program, but my CTRL+F-ing did not discover that bit about md5.

    I wanted to report back that bvdet's suggestion, something a la

    Code:
    text = Text(root)
    text.grid()
    text.bind('<Key>', compare)
    
    def compare(args*):
           # check the text
    seems to do the trick, apart from the fact that...
    See more | Go to post

    Leave a comment:


  • Per the title, I am using the Text widget (the text will normally contain several lines). The Text widget does not appear to have a 'textvariable' option.

    Going to try out bvdet's suggestions now.
    See more | Go to post

    Leave a comment:


  • nihilium
    started a topic Tkinter text widget - check if the text is edited

    Tkinter text widget - check if the text is edited

    Using Tkinter in Python 2.7.

    What I need is to be able to check regularly if the text in the widget has been changed. Ideally, I would have been able to call a function each time a change to the text was made or the widget was used, but this seems impossible.

    More specifically, I want to be able to have a label change between "original", "altered", "empty" and "new". Where e.g....
    See more | Go to post

  • nihilium
    started a topic Tkinter and commands

    Tkinter and commands

    With a right click, a popup menu will appear, allowing to select from a list of colours. The queston is: is it necessary to create a callback function for each colour? How may I pass on information to the callback function?

    Here's a short example script:

    [CODE=Python]
    from Tkinter import *

    root = Tk()

    def colour():
    print 'Which colour was it?'
    # Here, the actual...
    See more | Go to post

  • nihilium
    replied to Utilizing unicode strings
    So if I use

    [CODE=python]outputFile= codecs.open('ou tputFile.txt', 'w', 'utf-8')[/CODE]

    how do I then implement newline, \n, ?...
    See more | Go to post

    Leave a comment:


  • nihilium
    started a topic Utilizing unicode strings

    Utilizing unicode strings

    Ok, I am having some trouble handling unicode strings. Let's say that the file example.txt contains the word Ångström. When I put the u in front of '%s' I'll get the error below. Without the u, the text will not show up properly.

    [CODE=python]
    import re
    inputfile = file('C:/example.txt', 'r')
    inputfile = inputfile.read( )
    patt = re.compile(r'(. *)')
    m = patt.search(inp utfile)
    print u'%s'...
    See more | Go to post

  • nihilium
    replied to Unicode, lists & strings
    It turns out my problems do not lie where I thought they did. I'll have to do more research; thanks for the help....
    See more | Go to post

    Leave a comment:


  • nihilium
    started a topic Unicode, lists & strings

    Unicode, lists & strings

    A document contains text and notes below it. Both sections contains unicode. I want to add a disclaimer above the notelist.

    [CODE=python]import re
    f = open('C:/example.txt', 'r')
    source = f.read()
    patt = re.compile(r'(. *)[a-zA-Z\-]+\s?(?<![Error]):[^\[\]\n]*', re.DOTALL) # finding the main text
    text= patt.search(sou rce) # returns text containing unicode
    patt = re.compile(r'[a-zA-Z\-]+\s?(?<![Error]):[^\[\]\n]*')...
    See more | Go to post

  • That works, thanks again. The range should look like this, though:

    [CODE=Python]

    re.compile(r'si ze=\"\+1\"\>\<b \>(2[0-9][0-9][1-9]|2[1-9][0-9][0-9]|2[0-9][1-9][0-9]|3000) \w+')
    [/CODE]

    as your solution did not match the range 2010-2099....
    See more | Go to post

    Leave a comment:


  • How to subtract/add from/to a value found using the RE module?

    The beginning of the script goes like this.

    [CODE=python]import urllib2
    request = urllib2.urlopen ('http://ssd.jpl.nasa.go v/sbdb.cgi?sstr=2 000')
    source= request.read()
    import re
    name = re.compile(r'si ze=\"\+1\"\>\<b \>(\d+) (\w+)')
    thename = name.search(sou rce)[/CODE]

    Now I want to subtract 1 from as well as add 1 to [CODE=python]thename.group(1 )[/CODE]
    ...
    See more | Go to post

  • I finally understood this script, and it turns out it's just what I was looking for. Thanks!...
    See more | Go to post

    Leave a comment:


  • Ok, thanks for the help so far. I'm not so familiar with Python, so I didn't quite get how to use the script.

    Let's say that the text that needs to be replaced is in the document C:/Documents and Settings/example.txt, so I want to replace the text in that document as an automated process by running this script. For example I want to translate English dates into another language: December 2 should become 2. desember, where the number...
    See more | Go to post

    Leave a comment:


  • Using python as a search and replace macro; how to implement an unknown value

    I've searched a bit for this, but haven't stumbled upon anything that is useful for me yet. My question is pretty simple; I have the following script:

    inputFile = file('C:/Documents and Settings/example.txt', 'r')
    data = inputFile.read( )
    inputFile.close ()
    data = data.replace('t his x something', 'that x something else')
    outputFile = file ('C:/Documents and Settings/example.txt', 'w')
    outputFile.writ e(data)
    ...
    See more | Go to post
No activity results to display
Show More
Working...