| Reply | « Previous Thread | Next Thread » |
|
import codecs
import os, os.path path1 = u"C:\\Data\\MyApp\\temp.ini" newline = "\n" def init_settings(): f = codecs.open(path1, 'w', 'utf_8') settings = "variable_1" + newline settings += "variable_2" + newline settings += "variable_3" + newline f.write(settings) f.close() def mk_dir(): if not os.path.exists(path1): os.makedirs(path1) mk_dir() init_settings() problem: the directory along with file is getting created but there is no data inside, emulator gives an IO error -Permission denied |
| jiten_shah18 |
| View Public Profile |
| Find all posts by jiten_shah18 |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Offline
Forum Nokia Champion
|
|
That's because you're creating the directory named temp.ini, and then trying to write to it as if it were a file. So call os.makedirs with the path C:\\Data\\MyApp, as C:\\Data\\MyApp\\temp.ini is the path of the file.
And please use the CODE tags when posting code (the button with the # symbol on it in the post editor). That keeps the code indented and easy to read. |
|
thanx for ur help,it worked
can you tell me why it is creating only C:\MyApp folder instead of C:\Data\MyApp |
| jiten_shah18 |
| View Public Profile |
| Find all posts by jiten_shah18 |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Offline
Forum Nokia Champion
|
|
That's strange... If you use os.makedirs("C:\\Data\\MyApp") it should create the folder C:\Data\MyApp. That's what it did when I tried it.
|
|
Quote:
You can check using Code:
import os
os.listdir('c:')
os.listdir('c:\\Data')
|
| mahesh.sayibabu |
| View Public Profile |
| Find all posts by mahesh.sayibabu |
|
hello mahesh.sayibabu,
yeah i am sure its creating c:\Myapp instead of c:\Data\Myapp and even the code given by u has no output may i know what is the reason? |
| jiten_shah18 |
| View Public Profile |
| Find all posts by jiten_shah18 |
|
Check with this code. It is tested on E71 with PyS60 1.9.6
The directory, file and the file contents are created as expected. Code:
import codecs
import os, os.path
dir_path = u"C:\\Data\\MyApp"
file = "temp.ini"
newline = "\n"
def init_settings():
f = codecs.open(os.path.join(dir_path, file), 'w', 'utf_8')
settings = "variable_1" + newline
settings += "variable_2" + newline
settings += "variable_3" + newline
f.write(settings)
f.close()
def mk_dir():
if not os.path.exists(dir_path):
os.makedirs(dir_path)
mk_dir()
init_settings()
|
| mahesh.sayibabu |
| View Public Profile |
| Find all posts by mahesh.sayibabu |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Cannot create sis package? | gomcoite | Themes/Carbide.ui | 4 | 2008-09-27 18:54 |
| Error in packaging process :( | a-eqla3 | Themes/Carbide.ui | 2 | 2008-07-30 23:03 |
| Error in packaging process :( | a-eqla3 | Carbide.c++ IDE and plug-ins | 1 | 2008-07-24 21:33 |
| ERROR IN CREATING THEME | ssmantri | Themes/Carbide.ui | 5 | 2008-05-29 21:58 |
| Creating a directory in a root directory | ajitnair | Mobile Java General | 3 | 2007-11-07 16:48 |