User Profile

Collapse

Profile Sidebar

Collapse
bigturtle
bigturtle
Last Activity: Feb 5 '09, 01:22 PM
Joined: Apr 17 '07
Location: Neijiang, Sichuan, China
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • bigturtle
    replied to Pickling Unicode
    Yay Python 3!

    I have now switched to Python 3.0 and find that most of my problems have gone away. The pickle module works fine for Unicode, since all strings are anyhow Unicode. So no more u'...' in front of Unicode strings.

    FYI here are some things I had to watch out for. There is no more codecs module, and so Unicode input files are specified by

    FH = open(FileName, 'r', encoding='utf-8')

    and...
    See more | Go to post

    Leave a comment:


  • bigturtle
    replied to Pickling Unicode
    In your example, you have included in your test string 'ü' (ASCII 252 = u'\xFC') but not 'ǘ' (Unicode u'\u01D8'). It appears that there are three classes of characters:
    . 7-bit ASCII (0-127 = u'\x00' - u'\x7F')
    . "upper ASCII" (128-255 = u'\x80' - u'\xFF')
    . full 2-byte Unicode (u'\u0100' - u'\uFFFF')
    Codes 128-255 give problems to some routines because they are neither straight ASCII nor 2-byte Unicode....
    See more | Go to post

    Leave a comment:


  • bigturtle
    replied to Pickling Unicode
    Finally got your solution to work. There are a couple of things I don't understand about it.

    I like the idea: you flatten all the Unicode out of the string by changing all the Unicode to ASCII encodings, store it in a file as ASCII, then read it in and reverse the process. Here's a version that works for me.
    Code:
    import codecs
    import cPickle
     
    str1 = u'lǘelü'
    print "Pickling"
    print "str1
    ...
    See more | Go to post

    Leave a comment:


  • bigturtle
    started a topic Pickling Unicode

    Pickling Unicode

    Using Python 2.6, I am trying to pickle a dictionary (for Chinese pinyin) which contains both Unicode characters in the range 128-255 and 4-byte Unicode characters. I get allergic reactions from pickle.dump() under all protocols.

    Here’s a simple test program:
    Code:
    # Program 1 (protocol 0), program 2 (protocol 2)
      PickleFile = codecs.open('PFile.utf', 'w', 'utf-8')    
      Str1 = u'lǘelü' 
      pickle.dump(Str1,
    ...
    See more | Go to post

  • bigturtle
    replied to sqlite3/python dumb question
    Got it myself

    Figured it out on my own, thanks to Peyton McCulloch's tutorial at
    Using SQLite in Python.

    You retrieve the results of cursor.execute( ) using the fetchall() or fetchmany() method from the cursor class. So rewriting the last line of the snippet above gives

    Code:
    db.execute( "SELECT COUNT(*) FROM thefile" )
    Result = db.fetchall()
    NRecs = Result[0][0]
    In general,...
    See more | Go to post

    Leave a comment:


  • bigturtle
    started a topic sqlite3/python dumb question

    sqlite3/python dumb question

    I'm trying to do some database stuff in Python 2.6 with sqlite3, and am having trouble understanding the basics of the interface between the two. I am able to create database files and retrieve records, but some other commands are mysterious.

    Here's a snippet where I'm trying to retrieve the number of records in file "thefile", located in database "mydata" in sister folder "data":

    Code:
    
    
    ...
    See more | Go to post

  • bigturtle
    replied to Calculation of hours worked
    Do what bvdet says -- don't just look at your own thread! Instead, go all the way up to the top of the window above your thread, where it says "bytes > topic > python > answers", and click on "answers". Then you will see the "New Thread" button.

    If you learn how the forum works, you will be so much more productive and people will be more willing to help you.
    See more | Go to post

    Leave a comment:


  • bigturtle
    replied to What is your OS and Python Version
    I'm using Python 2.6 (with the included sqlite3) and Komodo 5 under WinXP Pro, nothing else special. I'm trying to make a flashcard program for Chinese, since I can't find one I like that's already made.

    So far I have worked out how to use Unicode special characters for syllables with tone marks, and how to convert syllables with tone marks back & forth from syllables with tone numbers (e.g. cōng, nǚ <--> cong1,...
    See more | Go to post

    Leave a comment:


  • bigturtle
    replied to regionalization problems
    Ughh!! I was afraid the answer would be something like this.

    Of course it is useful to know that horrible tweaking of this kind is unavoidable. And so my credibility with my client will be increased, if nothing else.

    Thanks for your help, JosAH.
    See more | Go to post

    Leave a comment:


  • bigturtle
    started a topic regionalization problems

    regionalization problems

    Is it possible to translate a program having some original-language material hard-coded in the original code?

    My client is Dr. S, a medical doctor from Japan specializing in occupational health, who is working as a postdoctoral fellow here in Canada. He has done a study in Japan using an aptitude test developed under the direction of Dr. K, a well-known Japanese occupational health specialist, in collaboration with a Japanese government...
    See more | Go to post

  • bigturtle
    replied to numerical cell entry problem
    Rabbit, your solution is fine if he wants to edit away the mistakes he made by entering the stuff as numbers.

    My point is that If he enters the values preceded by a double quote when he first enters them, then he doesn't have to fiddle around and edit leading zeros later. If the entries are text from the beginning, then these problems can't arise. Why ask for mistakes by starting out wrong??
    See more | Go to post
    Last edited by bigturtle; May 15 '07, 12:38 PM. Reason: incomplete answer

    Leave a comment:


  • bigturtle
    replied to numerical cell entry problem
    Easier: precede each entry with a double quote (") when you enter it, thus making it right-justified text in the first place. No need to add in leading zeros or whatever. Thus for 00012345 enter "00012345 (double quote only at beginning). Works in any spreadsheet program!
    See more | Go to post

    Leave a comment:


  • bigturtle
    replied to handling input and output data in files
    in C
    The easy way to do it is to store just the input in the input file. Thus in your example your input file would contain just, say,

    1.0 1.0 1.0
    10
    298

    I'm assuming, perhaps wrongly, that this is a simple program, and that you are always reading the same items in the same order. The text 'boxlengthX', 'radius (nm)' etc are just documentation so that you can read the input file and make changes to the right...
    See more | Go to post

    Leave a comment:


  • If the range of values is small, e.g. 0-10 as in your example, you can solve your problem with a single pass through the array. Set up a counting array NrA[] of integers, with one element for each possible value in your original array A[]. Zero all elements of NrA. Then go through A and for each element, say V = A[J], add 1 to NrA[V], the number of occurrences of value V. When you're finished, the counting array will contain, for each V, the # of...
    See more | Go to post

    Leave a comment:


  • bigturtle
    replied to simple excel questions
    Your "numbers" are actually text, since you are not performing computations on them. So type each one starting with a quote mark to make it text. Single quote will left-align the number in the cell, double quote will right-align it, ^ will center. Thus to right-align your sample number, type "12345678 (note: only the one quote at the beginning). This alignment can be changed later with an alignment command from the main menu....
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...