2007年06月19日 星期二 20:25
CÊÇÕâÑùµÄ. struct name_info { char _name[64]; int _idx; } //´ò¿ªÒ»¸öÎļþ _file; struct name_info _name; for(char i='a'; i<'z'; i++) { _name._name[0] = i; _name._idx = 0; fwrite(_file, (char*)&_name, sizeof(struct name_info)); } //¹Ø±ÕÎļþ _file; ³õѧPython, Õæ²»ÖªµÀÕâ¶Î´úÂëÓà pythonÔõôд£¬Çë´Í½Ì. -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070619/6ae27f06/attachment.htm
2007年06月19日 星期二 20:32
CÖеĽṹÔÚC++ÖпÉÒÔÓÃÀàÀ´ÃèÊö£¬PythonÖÐ×ÔȻҲ¿ÉÒÔ¡£ On 6/19/07, ³È×Ó <eyeonme在gmail.com> wrote: > > CÊÇÕâÑùµÄ. > > struct name_info > { > char _name[64]; > int _idx; > } > > //´ò¿ªÒ»¸öÎļþ _file; > struct name_info _name; > for(char i='a'; i<'z'; i++) > { > _name._name[0] = i; > _name._idx = 0; > > fwrite(_file, (char*)&_name, sizeof(struct name_info)); > } > //¹Ø±ÕÎļþ _file; > > ³õѧPython, Õæ²»ÖªµÀÕâ¶Î´úÂëÓà pythonÔõôд£¬Çë´Í½Ì. > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Uraka.Lee @ School of Software and Micro-electronic, Peking University, China -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070619/45c1005b/attachment.html
2007年06月19日 星期二 21:09
你的 fwrite() 错了吧 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); python 的话, 你可以试试 file object, 但我不确定它是否能用于 r/w binary file. 橙子 写道: > C是这样的. > > struct name_info > { > char _name[64]; > int _idx; > } > > //打开一个文件 _file; > struct name_info _name; > for(char i='a'; i<'z'; i++) > { > _name._name[0] = i; > _name._idx = 0; > > fwrite(_file, (char*)&_name, sizeof(struct name_info)); > } > //关闭文件 _file; > > 初学Python, 真不知道这段代码用 python怎么写,请赐教. > > > ------------------------------------------------------------------------ > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese
2007年06月19日 星期二 21:13
file("...", "rw") it is ok On 6/19/07, huanghao.c <huanghao.c在gmail.com> wrote: > > ÄãµÄ fwrite() ´íÁË°É > > size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE > *stream); > > python µÄ»°, Äã¿ÉÒÔÊÔÊÔ file object, µ«ÎÒ²»È·¶¨ËüÊÇ·ñÄÜÓÃÓÚ r/w binary file. > > > ³È×Ó Ð´µÀ: > > CÊÇÕâÑùµÄ. > > > > struct name_info > > { > > char _name[64]; > > int _idx; > > } > > > > //´ò¿ªÒ»¸öÎļþ _file; > > struct name_info _name; > > for(char i='a'; i<'z'; i++) > > { > > _name._name[0] = i; > > _name._idx = 0; > > > > fwrite(_file, (char*)&_name, sizeof(struct name_info)); > > } > > //¹Ø±ÕÎļþ _file; > > > > ³õѧPython, Õæ²»ÖªµÀÕâ¶Î´úÂëÓà pythonÔõôд£¬Çë´Í½Ì. > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- ÎÒ×ßµ½Ò»¸öÄ°ÉúµÄµØ·½, ¸æËß±ðÈË ÎÒҪȥÁ÷ÀË Å¶£¬ÎÒҪȥÁÆÉË¡¡ Gtalk: iexper(at)gmail.com ÓòÃû¹ýÆÚÁË -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070619/841cdcbc/attachment.htm
2007年06月19日 星期二 21:57
α´úÂë ÔÚ07-6-19£¬´óÀÉ <iexper在gmail.com> дµÀ£º > > file("...", "rw") > it is ok > > > On 6/19/07, huanghao.c <huanghao.c在gmail.com> wrote: > > > > ÄãµÄ fwrite() ´íÁË°É > > > > size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE > > *stream); > > > > python µÄ»°, Äã¿ÉÒÔÊÔÊÔ file object, µ«ÎÒ²»È·¶¨ËüÊÇ·ñÄÜÓÃÓÚ r/w binary file. > > > > > > ³È×Ó Ð´µÀ: > > > CÊÇÕâÑùµÄ. > > > > > > struct name_info > > > { > > > char _name[64]; > > > int _idx; > > > } > > > > > > //´ò¿ªÒ»¸öÎļþ _file; > > > struct name_info _name; > > > for(char i='a'; i<'z'; i++) > > > { > > > _name._name[0] = i; > > > _name._idx = 0; > > > > > > fwrite(_file, (char*)&_name, sizeof(struct name_info)); > > > } > > > //¹Ø±ÕÎļþ _file; > > > > > > ³õѧPython, Õæ²»ÖªµÀÕâ¶Î´úÂëÓà pythonÔõôд£¬Çë´Í½Ì. > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > python-chinese > > > Post: send python-chinese在lists.python.cn > > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > > Unsubscribe: send unsubscribe to > > python-chinese-request在lists.python.cn > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > -- > ÎÒ×ßµ½Ò»¸öÄ°ÉúµÄµØ·½, ¸æËß±ðÈË ÎÒҪȥÁ÷ÀË > Ŷ£¬ÎÒҪȥÁÆÉË¡¡ > > Gtalk: iexper(at)gmail.com > ÓòÃû¹ýÆÚÁË > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070619/bdd108ae/attachment.htm
2007年06月24日 星期日 21:12
Try this: class name_info: pass f=open(FILENAME,'wb') f._name = 'a' f._idx=0 f.write(name_info) f.close() On 6/19/07, 橙子 <eyeonme at gmail.com> wrote: > C是这样的. > > struct name_info > { > char _name[64]; > int _idx; > } > > //打开一个文件 _file; > struct name_info _name; > for(char i='a'; i<'z'; i++) > { > _name._name[0] = i; > _name._idx = 0; > > fwrite(_file, (char*)&_name, sizeof(struct name_info)); > } > //关闭文件 _file; > > 初学Python, 真不知道这段代码用 python怎么写,请赐教. > > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to > python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request at lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese >
2007年06月26日 星期二 09:27
лл Shuning Hong . »¹ÊǸоõpythonµÄÎļþ²Ù×÷²»ÊǺܷ½±ã. Èç¹û class name_info ÊÇÒ»Ìõ¼Ç¼,ÎÒÔÚÎļþÀïÃæÒѾдÁË 10Ìõ¼Ç¼ÁË. ÏÖÔÚÒª¸ÄдµÚÎåÌõµÄ¼Ç¼,ÈçºÎ²Ù×÷? 2007/6/24, Shuning Hong <hongshuning在gmail.com>: > > Try this: > > class name_info: > pass > > f=open(FILENAME,'wb') > f._name = 'a' > f._idx=0 > f.write(name_info) > f.close() > > > On 6/19/07, ³È×Ó <eyeonme在gmail.com> wrote: > > CÊÇÕâÑùµÄ. > > > > struct name_info > > { > > char _name[64]; > > int _idx; > > } > > > > //´ò¿ªÒ»¸öÎļþ _file; > > struct name_info _name; > > for(char i='a'; i<'z'; i++) > > { > > _name._name[0] = i; > > _name._idx = 0; > > > > fwrite(_file, (char*)&_name, sizeof(struct name_info)); > > } > > //¹Ø±ÕÎļþ _file; > > > > ³õѧPython, Õæ²»ÖªµÀÕâ¶Î´úÂëÓà pythonÔõôд£¬Çë´Í½Ì. > > > > > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to > > python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request在lists.python.cn > > Detail Info: > > http://python.cn/mailman/listinfo/python-chinese > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070626/833cc820/attachment.htm
2007年06月26日 星期二 09:33
On 6/26/07, 橙子 <eyeonme在gmail.com> wrote: > 谢谢 Shuning Hong . > > 还是感觉python的文件操作不是很方便. > > 如果 class name_info 是一条记录,我在文件里面已经写了 10条记录了. 现在要改写第五条的记录,如何操作? > python的写文件是随机存取的,而你要求的是按记录来处理的,这样一般要求每次记录是定长的,然后可以移动文件指针到指定的记录开始的位置,然后写入整条记录。 python的文件处理与C/C++是相同的。 -- I like python! UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou
2007年06月26日 星期二 09:52
ºÇºÇ. ÊÇÎÒ¸ã´íÁË. ¸Õ²Å×Ðϸ¿´ÁËһϠopen.__doc__ . ÔÀ´ÒªÒÔ ("r+") µÄ·½Ê½´ò¿ªÎļþ. "w" »áÇå¿ÕÎļþ. "a" Ö»»áÌí¼ÓÊý¾Ýµ½Î²²¿. ÔÚ"a"ģʽÏÂ, seek. ºÃÏñûÓÃ. ·Ç³£¸Ðл´ó¼ÒµÄ»Ø¸´. лл! ÔÚ07-6-26£¬limodou <limodou在gmail.com> дµÀ£º > > On 6/26/07, ³È×Ó <eyeonme在gmail.com> wrote: > > лл Shuning Hong . > > > > »¹ÊǸоõpythonµÄÎļþ²Ù×÷²»ÊǺܷ½±ã. > > > > Èç¹û class name_info ÊÇÒ»Ìõ¼Ç¼,ÎÒÔÚÎļþÀïÃæÒѾдÁË 10Ìõ¼Ç¼ÁË. ÏÖÔÚÒª¸ÄдµÚÎåÌõµÄ¼Ç¼,ÈçºÎ²Ù×÷? > > > > pythonµÄдÎļþÊÇËæ»ú´æÈ¡µÄ£¬¶øÄãÒªÇóµÄÊÇ°´¼Ç¼À´´¦ÀíµÄ£¬ÕâÑùÒ»°ãÒªÇóÿ´Î¼Ç¼ÊǶ¨³¤µÄ£¬È»ºó¿ÉÒÔÒƶ¯ÎļþÖ¸Õëµ½Ö¸¶¨µÄ¼Ç¼¿ªÊ¼µÄλÖã¬È»ºóдÈëÕûÌõ¼Ç¼¡£ > > pythonµÄÎļþ´¦ÀíÓëC/C++ÊÇÏàͬµÄ¡£ > > -- > I like python! > UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad > My Blog: http://www.donews.net/limodou > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070626/2323d843/attachment.html
Zeuux © 2025
京ICP备05028076号