Python-IOError: [Errno 13] Permiso denegado:
Estoy recibiendo IOError: [Errno 13] Permission denied
y no se lo que está mal con este código.
Estoy tratando de leer un archivo dado una ruta absoluta (lo que significa solo file.asm
),
Y una ruta relativa (que significa /.../file.asm
), y quiero que el programa escriba el archivo en cualquier ruta que se le dé - si es absoluta, debería escribirlo en el directorio actual; de lo contrario, en la ruta dada.
El código:
#call to main function
if __name__ == '__main__':
assem(sys.argv[1])
import sys
def assem(myFile):
from myParser import Parser
import code
from symbolTable import SymbolTable
table=SymbolTable()
# max size of each word
WORD_SIZE = 16
# rom address to save to
rom_addrs = 0
# variable address to save to
var_addrs = 16
# new addition
if (myFile[-4:] == ".asm"):
newFile = myFile[:4]+".hack"
output = open(newFile, 'w') <==== ERROR
El error dado:
IOError: [Errno 13] Permission denied: '/Use.hack'
La forma en que ejecutoel código:
python assembler.py Users/***/Desktop/University/Add.asm
¿Qué estoy haciendo ¿mal aquí?
8 answers
Parece Que estás tratando de reemplazar la extensión con el siguiente código:
if (myFile[-4:] == ".asm"):
newFile = myFile[:4]+".hack"
Sin embargo, parece que los índices del array están mezclados. Prueba lo siguiente:
if (myFile[-4:] == ".asm"):
newFile = myFile[:-4]+".hack"
Tenga en cuenta el uso de -4
en lugar de solo 4
en la segunda línea de código. Esto explica por qué su programa está tratando de crear /Use.hack
, que es el primero cuatro caracteres de su nombre de archivo (/Use
), con .hack
adjunto.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-05-13 23:00:10
Simplemente cierre el archivo abierto donde va a escribir.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-12 11:20:19
No tiene suficientes permisos para escribir en el directorio raíz. ¿Ves la barra diagonal en el nombre del archivo?
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-05-13 22:33:03
Esto me pasó cuando estaba usando 'shutil.copyfile 'en lugar de' shutil.copiado. Los permisos estaban mal.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-03 21:34:37
Tal vez esté tratando de abrir la carpeta with open
, compruébelo una vez.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-14 08:59:31
Para mí nada de lo alto funcionó. Así que resolví mi problema con esta solución. Simplemente compruebe que ha agregado el SISTEMA en la carpeta del directorio. Espero que ayude a somoene.
import os
# create file
@staticmethod
def create_file(path):
if not os.path.exists(path):
os.system('echo # > {}'.format(path))
# append lines to the file
split_text = text_file.split('\n')
for st in split_text:
os.system('echo {} >> {}'.format(st,path))
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-17 11:20:32
Por supuesto que puedes. Intenta cambiar esta línea:
output = open(newFile, 'w')
A:
output = open("./%s" % (newFile), 'w')
Debería guardar su archivo en el directorio local.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-05-13 22:40:09
Para mí, esto fue un problema de permisos.
Utilice la aplicación 'Take Ownership' en esa carpeta específica. Sin embargo, esto a veces parece funcionar solo temporalmente y no es una solución permanente.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-10 12:41:05