小编Byt*_*hon的帖子

使用python创建新文本文件时出错?

此功能不起作用并引发错误.我需要更改任何参数或参数吗?

import sys

def write():
    print('Creating new text file') 

    name = input('Enter name of text file: ')+'.txt'  # Name of text file coerced with +.txt

    try:
        file = open(name,'r+')   # Trying to create a new file or open one
        file.close()

    except:
        print('Something went wrong! Can\'t tell what?')
        sys.exit(0) # quit Python

write()
Run Code Online (Sandbox Code Playgroud)

python file-io file python-3.x

69
推荐指数
3
解决办法
27万
查看次数

将许多python变量列表保存到excel表中,同时保持定义变量类型?

使用xlsxwriter可以将变量保存到现有的excel文件并在之后读取它们,尽管问题是变量在excel文件中存储为字符串.

假设我有各种类型的许多不同变量的列表(pd.datetimerange,pd.df,np.arrays等),如果我将它们保存到excel文件中,变量类型将丢失.

Python脚本也是从我的Excel文件中调用的,因此如果不编写VBA脚本,我就无法更改其中的任何内容.哪个会暂时关闭我的工作簿,转储字符(比如说pickle字符串)并重新打开它.

是否可以从excel文件中检索类型而无需先编写解析函数(这将采用excel字符串并使用等效的变量类型产生)?

python parsing vba pandas xlsxwriter

17
推荐指数
1
解决办法
439
查看次数

在OSX 10.8.4上卸载Python 2.7

主要问题: 我最近安装了Python3.3 - 如果我现在在终端运行:( python script.py其中script.py在版本3.3中编码)我会得到一个python 2.7输出,例如:

print('String',Var) --> ('String',Var) 
Instead of:
print('String, Var) --> String Var 
Run Code Online (Sandbox Code Playgroud)

如何使用Macport轻松卸载Python 2.7(无需读取Shell命令(时间限制)?) 这个没有用.

第二个(较小的)问题: 如果我输入终端python,我将把python2.7作为输出空闲.我怎么能改变这个,所以命令python引用python3.3(而不是使用命令python3)

(关于我:Python2.7新手,绝对没有Shell知识,OS X 10.8.4用户,Xcode和Macport安装.)

python macos uninstall

4
推荐指数
1
解决办法
8780
查看次数

标签 统计

python ×3

file ×1

file-io ×1

macos ×1

pandas ×1

parsing ×1

python-3.x ×1

uninstall ×1

vba ×1

xlsxwriter ×1