我有一个使用
创建的文本文件 open(new_file_name_string,"w+")
我想知道是否/如何使用open函数(或任何其他python函数)来创建python(.py)文件而不是文本(.txt)文件。例如,我可以使用与" w +"不同的参数。 make open生成一个python文件?
如果没有这样的可用,是否有一个python函数可以将我的.txt文件转换为.py文件?
答案 0 :(得分:1)
如果您想要更改扩展名,只需更改文件名即可。如果您之前的文件名只是%macro print 2 ;print on monitor
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro accept 2 ;accept from user
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro exit 0
mov rax,60
mov rdi,0
syscall
%endmacro
%macro fopen 1
mov rax,2
mov rdi,%1 ;name of file
mov rsi,2
mov rdx,0777o
syscall
%endmacro
%macro fread 3
mov rax,0
mov rdi,%1
mov rsi,%2
mov rdx,%3
syscall
%endmacro
%macro fwrite 3
mov rax,1
mov rdi,%1
mov rsi,%2
mov rdx,%3
syscall
%endmacro
%macro fclose 1
mov rax,3
mov rdi,%1
syscall
%endmacro
section .data
msg db 10,"Enter file_name to open : "
len equ $-msg
msg4 db 10 ,"written into file "
len4 equ $-msg4
msg5 db 10 ,"Not written success "
len5 equ $-msg5
section .bss
fname1 resb 17 ;1 for enter
fdesc resb 8
buff resb 103
bufflen resb 8
section .code
global _start
_start:
print msg,len
accept fname1,20
dec rax
mov byte[fname1+rax],0
fopen fname1
mov [fdesc],rax
fread [fdesc],buff,100
dec rax
mov [bufflen],rax
print buff,[bufflen]
fwrite [fdesc],msg4,len4
cmp rax,0FFFFFFFFFFFFFFFEH
je haha
print msg4,len4
exit
haha:
print msg5,len5
fclose fname1
exit
或filename
,只需将其更改为filename.txt