Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÊÖ¶¯ÖÆ×÷pythonµÄexe¿ÉÖ´ÐгÌÐò


1. ÊÖ¶¯ÖÆ×÷pythonµÄexe¿ÉÖ´ÐгÌÐò
                                      תÔØ---------------
PythonûÓÐÄÚ½¨Ò»¸ö±àÒëΪexeµÄ¹¦ÄÜ¡£¸øpython³ÌÐòµÄ²¿Êð´øÀ´²»ÉÙµÄÂé·³¡£
ËùÒԾͻá³öÏÖһЩpy2exeÖ®ÀàµÄºÜ²»´íµÄ¹¤¾ß£¬ÓÃÓÚ×Ô¶¯°Ñ.pyÎļþ±àÒëΪ.exeÎļþ¡£
×î½ü³é¿ÕÑо¿ÁËÒ»ÏÂÊÖ¶¯ÊµÏÖÀàËÆpy2exeµÄ¹¦ÄÜ£¬Ï£Íû¼ÓÇ¿¶ÔpythonµÄÁ˽⡣
½á¹û»¹Ï൱²»´í¡£°Ñ½á¹û¼Ç¼ÏÂÀ´£¬Óë´ó¼Ò¹²Ïí¡£
 
1.1. Ô­Àí
ÎÄÖÐËùÃèÊöµÄ·½·¨£¬»ùÓÚpythonµÄÒÔϼ¸¸ö¹¦ÄÜ
1. python³ÌÐòÔËÐÐʱ£¬»áÔÚsys.pathÖ¸¶¨µÄ·¾¶ÖвéÕÒ¿âÎļþ¡£
2. python´Ó2.3¿ªÊ¼£¬Ö§³Ö´ÓzipÎļþÖÐimport¿â(Ö§³Ö.py,.pycºÍ.pyo£¬µ«²»Ö§³Ö.pyd)
3. pythonÌṩC API£¬ÈÃcÓïÑԵijÌÐò£¬¿ÉÒԺܷ½±ãµÄµ÷ÓÃpythonµÄ³ÌÐò
 
1.2. ʵ¼Ê²½Öè
×¢£º¼ÙÉèpython°²×°ÔÚc:\python25Ŀ¼ÖУ¬×îºóµÄ¿ÉÖ´ÐÐÎļþ·Åµ½d:\distĿ¼ÖÐ
1. ÏÈÈ¥c:\python25\LibĿ¼£¬°ÑËùÓÐÎļþ¶¼¸´ÖƳöÀ´£¬±ÈÈ縴ÖƵ½d:\pythonlibĿ¼ÖÐ
2. ¿ªÒ»¸öcmd´°¿Ú£¬½øÈëd:\pythonlibĿ¼ÖУ¬ÔËÐРpython -OO compileall.py -f . °ÑlibÖеÄ.pyÎļþ¶¼±àÒë³É.pyoÎļþ
3. ɾ³ýd:\pythonlibĿ¼ÖÐËùÓеÄ.pyºÍ.pycÎļþ£¬ÒòΪÎÒÃÇÖ»ÒªÓÐ.pyoÎļþ¾Í¿ÉÒÔÈÃÕâЩ¿âÔËÐÐÁË¡£
4. ɾ³ýĿ¼ÖÐËùÓÐÓò»×ŵÄÎļþ£¬±ÈÈçcurses£¬test£¬idlelib£¬msilibµÈ£¬ÒÔ¼õÉÙÉú³ÉÎļþµÄÌå»ý¡£
5. °ÑÕâЩ¿â´ò°ü³ÉÒ»¸özipÎļþ£¬±ÈÈçstdlib.zip£¬·Åµ½d:\distĿ¼ÖÐ
6. °Ñc:\python25\dllsĿ¼ÖеÄ.pydºÍ.dllÎļþ£¬¸´ÖƵ½d:\dist\dllsĿ¼ÖУ¬µ±È»£¬É¾³ý²»¿ÉÄÜÓõ½µÄһЩÎļþ_msi.pyd,_ssl.pydµÈµÈ£¬¿ÉÒÔ¼õÉÙÎļþµÄÌå»ý
7. °Ñ×Ô¼ºÐ´µÄ³ÌÐò£¬Ò²°´²½Öè2ÖÁ²½Öè5Ëù˵µÄ·½·¨£¬´ò³ÉÒ»¸ömysrc.zip°ü£¬·Åµ½d:\distĿ¼ÖС£ ×¢Ò⣺×Ô¼ºÐ´µÄ³ÌÐòµÄÈë¿ÚÓ¦¸ÃÊÇmain.pyoÎļþ
8. ÓÃÒÔÏÂC³ÌÐò±àÒë³öÒ»¸ö¿ÉÖ´ÐÐÎļþ£¬±È·½Ëµ½Ðrunpy.exe£¬Ò²·Åµ½d:\distÖС£
 
#include <Python.h>
#include <Windows.h>
int main()
{
// µÃµ½µ±Ç°¿ÉÖ´ÐÐÎļþËùÔÚµÄĿ¼
char szPath[10240];
char szCmd[10240];
GetModuleFileName(NULL, szPath, sizeof(szPath));
char* p = strrchr(szPath,


Ïà¹ØÎĵµ£º

Python ÖеÄ×Ö·û±àÂë

1¡¢strÀàÐÍ¿ÉÒÔÀí½âΪһ¸ö¶þ½øÖÆblock£¬»òmultibyte
2¡¢multibyte_str.decode("<multibyte_encode_method>")  -> unicode
3¡¢unicode_str.encode("<multibyte_encode_method>")  -> multibyte_str(binary block)
4¡¢unicode_str µÄ²Ù×÷²ÎÊýҲӦΪunicode£¬È磺unicode_str.find("Ñù±¾".deco ......

ÈçºÎÔËÐÐPython½Å±¾

¼ÙÉèÄãÄãµÄ²Ù×÷ϵͳÊÇWinXP£º

¿ªÊ¼²Ëµ¥-> ÔËÐÐ-> cmd

È»ºó¾Í¿ÉÒÔÇÃÃüÁîÁË¡£

Èç¹ûÄãÓÃIDLE£¬¿ÉÒÔÓÃIDLE´ò¿ªÕâ¸ö.pyÎļþ£¬È»ºóÔڲ˵¥ "Run "ÏÂÓÐÒ»Ïî "Run   Module "£¬µã»÷¼´¿É¡£ ......

»°ËµPython£¨Èý£©Íò¶ñµÄ±àÂë

Íò¶ñµÄ±àÂë
С²Ë¶ÔÓÚÀÏʦÉÏÒ»½Ú½²µÄ²»ÊǺÜÃ÷°×£¬ÒòΪûÓÐÒ»±¾ÊéÊǽ«ÎļþÓëwebÒ»Æð½²Êڵģ¬Ëû¾ö¶¨×Ô¼ºÌ½¾¿Ò»ÏÂËüÃÇÖ®¼äµÄ²»Í¬£º
Ê×ÏÈ£¬Ð¡²ËÔÚCÅ̽¨ÁËÒ»¸öÎı¾Îĵµ file.txt,ÊäÈëËĸö×Ö£ºÎÒÊÇС²Ë¡£
È»ºó£¬Ð¡²ËÔÚshellÖÐÁ·Ï°ÆðÀ´£º
>>> file=open("c:\\file.txt","r")
>>> data=file.read()
>> ......

Python£¬¼òµ¥µÄÁ¦Á¿

Python£¬¼òµ¥µÄÁ¦Á¿
¶¹°êÍø¶Ô»¥ÁªÍøÓû§À´ËµÊÇÖªÃûµÄWeb 2.0ÉçÇø£¬µ«¶Ô¿ª·¢Õ߶øÑÔ£¬¸üÖØÒªµÄÊÇÒ»¸öÓ¦ÓÃPython´òÔìµÄ·Ç³£³É¹¦µÄWeb 2.0Õ¾µã¡£
Pythonµ®ÉúÒÑÓÐ20ÄêµÄÀúÊ·£¬Ä¿Ç°¹úÄÚµÄPython·¢Õ¹×´¿öÈçºÎ£¿ÓëÆäËûÓïÑÔ£¨Æ½Ì¨£©Ïà±È£¬PythonÓÐÄÄЩÏÔ¶øÒ×¼ûµÄÓŵ㣿¶¹°êÓ¦ÓÃPython½øÐÐWeb¿ª·¢ÓÐÄÄЩ³É¹¦¾­Ñé¿ÉÒÔ½è¼ø£¿´ø×ÅÕâЩΠ......

python¶ÁдÎļþ


1.open
ʹÓÃopen´ò¿ªÎļþºóÒ»¶¨Òª¼ÇµÃµ÷ÓÃÎļþ¶ÔÏóµÄclose()·½·¨¡£±ÈÈç¿ÉÒÔÓÃtry/finallyÓï¾äÀ´È·±£×îºóÄܹرÕÎļþ¡£
file_object = open('thefile.txt')
try:
     all_the_text = file_object.read( )
finally:
     file_object.close( )
×¢£º²»Ä ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ