0

Here's the scenario:

I am writing a program that will run inside a Telit HE910 GSM module, which has an on-board python interpreter. I would like my program to be able to read and store some parameters inside a configuration file onboard the GSM module. The file may occasionally be transferred into a separate machine for viewing and changing, so it should be both machine-readable and writeable on multiple platforms.

So far, there are multiple solutions for this issue. Here's the kicker though:

  • The GSM module does not have any python modules for parsing / writing configuration files (so I can't simply use import yaml, import json, import configparser, or even import csv)
  • The GSM module does not allow the creation of subdirectories. From my limited understanding, this prevents me from simply dumping the contents of say, the PyYAML python module into the GSM module and calling it from my program.

I found a similar question here, but I don't even know where in the GSM module's filesystem I am. import os doesn't seem to work, which is strange (contrary to documentation).

I know I can use a Python file to store some read-only configurations, but I also want to be able to write to the config file (redesigning the system to avoid this is really undesirable).

I think my best bet so far seems to be to write a simple csv parser / writer myself, unless someone has a better idea (or know how to utilise Python modules without any subdirectories).

PS: The documentation below has a list of supported modules. None of the config-related modules seem to be available however.

EDIT: I should have mentioned, the configuration file needs to be readable / writeable from a c# .NET application, not another python interpreter on the desktop.

Community
  • 1
  • 1
ssfivy
  • 3
  • 2

3 Answers3

2

You have _ast (§5.2.36), so it should be possible to reimplement ast.literal_eval(). At that point reading and writing becomes mostly trivial.

Community
  • 1
  • 1
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • This is really useful for reading, however I'm not sure on how this will be useful for writing though. Also, I should have specified that the config file needs to be cross-platform to C# .net, not another python interpreter on a desktop machine. – ssfivy Jul 17 '12 at 23:20
  • Writing is `print >>fp, repr(data)`. And IronPython. – Ignacio Vazquez-Abrams Jul 18 '12 at 00:04
  • Thanks, this should work (pending ironpython, need to talk to .net guy). – ssfivy Jul 18 '12 at 05:15
1

I wouldn't recommend it in normal Python usage, but a possible option would be the marshal module mentioned in 5.2.34 of the manual you posted, and description/limitations/warnings here: http://docs.python.org/library/marshal.html

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
  • Probably not very useful as it should be cross-platform to c# .net, sorry, should've mentioned it earlier. – ssfivy Jul 17 '12 at 23:36
0

Why don't you just open a txt file and store all info as a text file? I read the Easy Script Manual for your module, there is a posix module which supports methods like open, close, unlink.

foresightyj
  • 2,006
  • 2
  • 26
  • 40