[PythonCE] PythonCE - I'm a subscriber

Adam Walley adam.walley at gmail.com
Mon Feb 14 11:32:40 CET 2011


Hello, Ihsan.

In general, I find it easier to develop my code on one of my main systems
rather than directly on the mobile device (to transfer and test it on the
device I would then use ftp or a usb cable and activesync).

However, if you want to code and test directly on the mobile device, I
suggest the following steps (this is more of a workaround than a solution,
but it works reasonably well):

- create three plain text files on your device
   >>> f=open("/yourpath/infile.txt","wb")
   >>> f.write("mycode")
   >>> f.close()
   >>> f=open("/yourpath/mycode.txt","wb")
   >>> f.write("# python code\r\n")
   >>> f.close()
   >>> f=open("/yourpath/txt2py.txt","wb")
   >>> f.write("# txt2py renaming utility\r\n")
   >>> f.close()

(note: when in the python interpreter, you can tap a line you have already
typed and press enter/return, and it will appear at the '>>>' prompt so you
can modify it and enter it again - this is quicker than typing the whole
line again)

- now close python and open the 'txt2py.txt' file with the Windows Mobile
text editor (Notes or Word, I think), but remember that when you save the
file you must NOT let Notes change the format. Because it is a text file,
just tapping it should open it in the default editor. Enter the following
python code in the text editor:
   f=open("infile.txt","rb")
   fname=f.read()
   f.close()
   print "opening:",fname+".txt"
   f=open(fname+".txt","rb")
   fdat=f.read()
   f.close()
   print "saving:",fname+".py.py"
   f=open(fname+".py.py","wb")
   f.write(fdat)
   f.close()

Now back in python:
   >>> f=open("/yourpath/txt2py.txt","rb")
   >>> fdat=f.read()
   >>> f.close()
   >>> f=open("/yourpath/txt2py.py.py","wb")
   >>> f.write(fdat)
   >>> f.close()

That's it! Now you can modify the 'mycode.txt' file in your text editor.
When you have saved it you can run the 'txt2py' tool to make a copy of the
file with the '.py.py' extension. Why the double extension? This is just a
simple workaround to make your python files more visible, because Windows
Mobile hides the file extension. By using a simple text file to hold the
root of the filename to convert in 'infile.txt' you can easily modify the
name so 'txt2py' can rename any '.txt' file to a '.py.py' file. Once you
have one text file created, you can create a new text file by doing copy &
paste, then renaming it. Note that the suggestion I am making assumes you
are working with all your files in the same folder.

Of course, once you have it all working, you can work on improving the code.
For example, you could create a 'py2txt' tool.

This is just my suggestion. Others on the list may have better ideas(?).

Adam

On 13 February 2011 22:59, Ihsan Cingisiz <ihsan_cingisiz at live.nl> wrote:

>  Hello,
>
> I did all of this:
> >>> import _winreg as reg
> >>> k=reg.CreateKey(reg.HKEY_CLASSES_ROOT,'.py')
> >>> reg.SetValueEx(k,'Default',0,reg.REG_SZ,'Python.File')
> >>>
> k=reg.CreateKey(reg.HKEY_CLASSES_ROOT,'Python.File\\Shell\\Open\\Command')
> >>> reg.SetValueEx(k,'Default',0,reg.REG_SZ,'\"\\Storage
> Card\\Program Files\\python.exe\" \"%1\"')
>
> But I need help with editing and creating a .py file..
> Can you please help me?
>
> Thanks!
>
> K. Regards,
> Ihsan.
>
> ------------------------------
> Date: Thu, 10 Feb 2011 19:23:46 +0000
> From: adam.walley at gmail.com
> To: pythonce at python.org
> Subject: Re: [PythonCE] PythonCE - I'm a subscriber
>
>
> Hi, Ihsan.
>
> Welcome to the list. I am not sure what you mean by programming without the
> '>>>'s, but I have a feeling that you mean the Python interpreter is not
> associated with .py files. Once the association is created in the registry,
> you can launch .py files. I use WM5, but I think WM6.1 will probably let you
> do this too. To create the association in the registry you need to start the
> Python interpreter on your device, and yes you need to use the '>>>'s, but
> only for these steps:
>
> >>> import _winreg as reg
> >>> k=reg.CreateKey(reg.HKEY_CLASSES_ROOT,'.py')
> >>> reg.SetValueEx(k,'Default',0,reg.REG_SZ,'Python.File')
> >>>
> k=reg.CreateKey(reg.HKEY_CLASSES_ROOT,'Python.File\\Shell\\Open\\Command')
> >>> reg.SetValueEx(k,'Default',0,reg.REG_SZ,'\"\\Storage
> Card\\Program Files\\python.exe\" \"%1\"')
>
> DISCLAIMER: please be aware that modifying the registry can cause serious
> problems with your operating system. Do not undertake any changes unless you
> know and understand what you are doing!
>
> The above lines of code may get broken through the email and/or mailing
> list, so check them carefully! Also remember the underscore for the
> '_winreg' module name, and look carefully at the string value you need to
> enter for the path to the Python.exe file - there are single AND double
> quotation marks.
>
> When you have completed the above steps, you should be able to launch a
> simple .py file containing Python code without needing to open the
> interpreter first.
>
> Note that I prefer to run my Python executable from an SD card, so the
> registry path begins with '\\Storage Card\\Program Files\\...', but if your
> Python.exe is located on the main device, the value will probably simply
> begin '\\Program Files\\...'.
>
> Alternatively, if you are able to establish an ActiveSync link with your
> computer and device, then you can download a registry editor to make the
> task easier (e.g. CERegEditor by MDSoft is one, but there are many).
>
> Now, writing and editing .py files is another matter...
>
> HTH
>
> Adam
>
> On 10 February 2011 16:23, Ihsan Cingisiz <ihsan_cingisiz at live.nl> wrote:
>
>  Hello,
>
> I download PythonCE today because I love programming in Python, i'm using
> it on
> my computer and wanted to use it on my HTC Touch Pro with Windows Mobile
> 6.1.
> It work, but only the 'IDLE', I mean this for example:
> >>> print "Hello..."
>
> In Python PC Version you can do open a new window and program without the
> >>>'s.
> Is that possible in PythonCE too? If it is, how do I open it?
>
> Kind Regards,
> I. Cingisiz.
>
> _______________________________________________
> PythonCE mailing list
> PythonCE at python.org
> http://mail.python.org/mailman/listinfo/pythonce
>
>
>
> _______________________________________________ PythonCE mailing list
> PythonCE at python.org http://mail.python.org/mailman/listinfo/pythonce
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonce/attachments/20110214/d9afc70c/attachment.html>


More information about the PythonCE mailing list