开发者

String resources in python (google app engine)

开发者 https://www.devze.com 2023-02-26 19:27 出处:网络
How does one work with string resources in python/gae in eclipse+pydev environment? looking for 开发者_开发知识库something that is the equivalent of this link. Also, what is the recommended approach f

How does one work with string resources in python/gae in eclipse+pydev environment? looking for 开发者_开发知识库something that is the equivalent of this link. Also, what is the recommended approach for working with large strings? Create a text file as part of your app and use file I/O, or something else?


for those still seeking a solution for string resources file on GAE and Python (2.7), I used a YAML formated file:

  1. create a file named "strings.txt" (for example), it's content can be something like this:

    level_1_name: this is a text
    
    # this is a comment
    test:
    - testtitle: test title
      testtitlechild: testtitlechild
    
  2. place this on the bottom of your main application file:

    # strings file (YAML format) initialization
    strings = yaml.load(open("strings.txt", "r"))
    
  3. then you get 'strings' as dict, using it goes as follows:

    strings["level_1_name"]
    


Assuming "string resource" is a fancy name for text-file, you have three choices;

  • If your large text file is read only then you can bundle it along with your other application files and access it as you would normally (via open() or similar method).

  • If your application needs to write lots of text-data then you will have to store it in the datastore using a TextProperty but beware there are limits on the amoount of data that can be written to the datastore in one go (currently 1MB) ... OR...

  • Use the Blobstore API to read/write files

0

精彩评论

暂无评论...
验证码 换一张
取 消