我的项目看起来像这样:
running-pycharm-project-at-cmd
- main.py
- c
- run_project.py
- z
- __init__.py
- the_module.py
- y
- __init__.py
- template.md
- the_module_module.py
- the_support_function.py
Run Code Online (Sandbox Code Playgroud)
.py文件的内容如下所示:
main.py
from c.run_project import run
print('running main.py...')
run()
Run Code Online (Sandbox Code Playgroud)
C/run_project.py
from c.z.the_module import the_module_function, the_module_write_function
def run():
print('Running run_project.py!')
the_module_function()
# write a file:
the_module_write_function(read_file='./z/y/template.md', write_file='../README.md')
if __name__ == '__main__':
run()
Run Code Online (Sandbox Code Playgroud)
C/Z/the_module.py
from c.z.y.the_module_module import the_module_module_function
def the_module_function():
print('the_module_function is running!')
the_module_module_function()
pass
def the_module_write_function(read_file, write_file):
with open(read_file, 'r') as fid:
with open(write_file, 'w') as fid_out: …Run Code Online (Sandbox Code Playgroud) 我正在使用Python.NET加载一个C#程序集来从Python调用C#代码.这非常干净,但我遇到一个问题,调用一个如下所示的方法:
Our.Namespace.Proj.MyRepo中的方法:
OutputObject GetData(string user, int anID, int? anOptionalID= null)
Run Code Online (Sandbox Code Playgroud)
我可以为存在可选的第三个参数的情况调用该方法,但是无法确定要为第三个参数传递什么以匹配null情况.
import clr
clr.AddReference("Our.Namespace.Proj")
import System
from Our.Namespace.Proj import MyRepo
_repo = MyRepo()
_repo.GetData('me', System.Int32(1), System.Int32(2)) # works!
_repo.GetData('me', System.Int32(1)) # fails! TypeError: No method matches given arguments
_repo.GetData('me', System.Int32(1), None) # fails! TypeError: No method matches given arguments
Run Code Online (Sandbox Code Playgroud)
iPython Notebook表明最后一个参数应该是类型:
System.Nullable`1[System.Int32]
Run Code Online (Sandbox Code Playgroud)
只是不确定如何创建一个与Null案例匹配的对象.
有关如何创建C#认可的Null对象的任何建议?我假设传递原生Python没有用,但事实并非如此.
我正在寻找使 Pandas DataFrame 列保持一致的优雅的 Pythonic 方式。意义:
我有以下示例有效,但是是否有内置的 Pandas 方法可以实现相同的目标?
import pandas as pd
df1 = pd.DataFrame(data=[{'a':1,'b':32, 'c':32}])
print df1
Run Code Online (Sandbox Code Playgroud)
美国广播公司 0 1 32 32
column_master_list = ['b', 'c', 'e', 'd', 'a']
def get_dataframe_with_consistent_header(df, headers):
for col in headers:
if col not in df.columns:
df[col] = pd.np.NaN
return df[headers]
print get_dataframe_with_consistent_header(df1, column_master_list)
Run Code Online (Sandbox Code Playgroud)
西达 0 32 32 NaN NaN 1
python ×3
.net ×1
c# ×1
command-line ×1
dataframe ×1
pandas ×1
pycharm ×1
python-3.x ×1
python.net ×1