file-io

python try:except:finally

让人想犯罪 __ 提交于 2020-04-05 07:25:12
问题 # Open new file to write file = None try: file = open(filePath, 'w') except IOError: msg = ("Unable to create file on disk.") file.close() return finally: file.write("Hello World!") file.close() The above code is ripped from a function. One of the user's system is reporting an error in line: file.write("Hello World!") error: AttributeError: 'NoneType' object has no attribute 'write' Question is, If python is failed to open given file, 'except' block executes and it has to return, but control

Why does os.path.getsize() return a negative number for a 10gb file?

微笑、不失礼 提交于 2020-03-14 08:49:18
问题 I am using the function os.path.getsize() which gives the size of the file in bytes. As my one file size is 10gb it give me size in negative(bytes). so can anyone give me any idea why this happen? This is my code: import os ospathsize = os.path.getsize('/home/user/Desktop/test1.nrg') print (ospathsize) 回答1: Your Linux kernel obviously has large file support, since ls -l works correctly. Thus, it's your Python installation that is lacking the support. (Are you using your distribution's Python

Why does os.path.getsize() return a negative number for a 10gb file?

匆匆过客 提交于 2020-03-14 08:46:56
问题 I am using the function os.path.getsize() which gives the size of the file in bytes. As my one file size is 10gb it give me size in negative(bytes). so can anyone give me any idea why this happen? This is my code: import os ospathsize = os.path.getsize('/home/user/Desktop/test1.nrg') print (ospathsize) 回答1: Your Linux kernel obviously has large file support, since ls -l works correctly. Thus, it's your Python installation that is lacking the support. (Are you using your distribution's Python

Read a HTML file into a string variable in memory

我的未来我决定 提交于 2020-03-13 04:39:11
问题 If I have a HTML file on disk, How can I read it all at once in to a String variable at run time? Then I need to do some processing on that string variable. Some html file like this: <html> <table cellspacing="0" cellpadding="0" rules="all" border="1" style="border-width:1px;border-style:solid;width:274px;border-collapse:collapse;"> <COLGROUP><col width=35px><col width=60px><col width=60px><col width=60px><col width=59px></COLGROUP> <tr style="height:20px;"> <th style="background-color:

Save XML file on Android device and read it

拟墨画扇 提交于 2020-03-06 02:18:30
问题 I have issues with storing and reading an XML file on my Acer Iconia Tab A 100. The steps I followed are: 1) Plug in the tab to my system. 2) Copy test.xml file from my laptop to Acer Iconia Tab/ SDCard/ mydir/test.xml 3) Try to open this file in Android code, as follows: File testFile = null; File dir = new File(android.os.Environment.getExternalStorageDirectory(),"mydir"); if(dir.exists()) testFile = new File(dir, "test.xml"); if (testFile != null) Log.d ("File length="+testFile.length());

Save XML file on Android device and read it

僤鯓⒐⒋嵵緔 提交于 2020-03-06 02:17:47
问题 I have issues with storing and reading an XML file on my Acer Iconia Tab A 100. The steps I followed are: 1) Plug in the tab to my system. 2) Copy test.xml file from my laptop to Acer Iconia Tab/ SDCard/ mydir/test.xml 3) Try to open this file in Android code, as follows: File testFile = null; File dir = new File(android.os.Environment.getExternalStorageDirectory(),"mydir"); if(dir.exists()) testFile = new File(dir, "test.xml"); if (testFile != null) Log.d ("File length="+testFile.length());

What events can cause ferror to return non-zero?

你。 提交于 2020-02-28 04:53:47
问题 What events can cause ferror() to return non-zero and after what events should one check ferror() ? http://www.cplusplus.com/reference/cstdio/ferror/ Opening, reading, closing? Will the return value of ferror() ever change spontaneously? E.g., if a program checks ferror(stream) , takes a nap without interacting with the FILE object associated with stream , and then checks ferror(stream) again, will the return value ever be different? Is any of this mandated by standards? 回答1: It is primarily

How can one delete files in a folder matching a regular expression using PowerShell?

落花浮王杯 提交于 2020-02-26 06:54:08
问题 I know a common characteristic of the file names of a number of unwanted files on my Windows computer. How can I remove all of these files from a given folder or folder hierarchy with a single regular expression PowerShell command? 回答1: You can pipe a Get-ChildItem command through a Where-Object filter that accepts a RegEx pattern, and then pipe that into Remove-Item. I think that will get you a faster, and better result than using Select-String. With a command like: Get-ChildItem $Path |

How can one delete files in a folder matching a regular expression using PowerShell?

末鹿安然 提交于 2020-02-26 06:53:01
问题 I know a common characteristic of the file names of a number of unwanted files on my Windows computer. How can I remove all of these files from a given folder or folder hierarchy with a single regular expression PowerShell command? 回答1: You can pipe a Get-ChildItem command through a Where-Object filter that accepts a RegEx pattern, and then pipe that into Remove-Item. I think that will get you a faster, and better result than using Select-String. With a command like: Get-ChildItem $Path |

c# change FileVersionInfo for any file

情到浓时终转凉″ 提交于 2020-02-24 14:30:13
问题 With FileVersionInfo class is very easy to read file extra information, but is there any way i can change it? Thanks. 回答1: There's no class in the .NET Framework that lets you do that easily. File version data is stored as a native resource, so it can be changed by functions like BeginUpdateResource. But it requires detailed knowledge about the format in which it's are stored in the executable. 来源: https://stackoverflow.com/questions/3785966/c-sharp-change-fileversioninfo-for-any-file