我正在尝试用来inspect.getmembers检查文件中的类和函数.问题是我不知道如何在inspect.getmembers不使用的情况下将文件名传递给import.那是因为我每次都需要指定一个不同的文件名
代码看起来类似于:
def extractName(self,fileName):
for name, obj in inspect.getmembers(FileName):
if inspect.isclass(obj):
print "this is class",name
if inspect.isfunction(obj):
print "this is method",name
Run Code Online (Sandbox Code Playgroud) 我已经按照教程将In App Purchase添加到我的应用程序中.有2次观看次数:
我已经完全添加了代码,但在教程中他们使用的是XIB文件,但我使用的是Storyboard.我的"购买项目"按钮的代码如下所示:
- (IBAction)PurchaseItem:(id)sender {
_purchaseController = [[PurchasedViewController alloc] initWithNibName:Nil bundle:nil];
_purchaseController.productID = @"com.myapp";
[self presentViewController:_purchaseController animated:YES completion:NULL];
[_purchaseController getProductID:self];
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当单击按钮时,会出现黑屏,但我希望BuysedViewController显示
我需要改变什么吗?
编辑:
使用已编辑的代码但收到附加错误:
- (IBAction)PurchaseItem:(id)sender {
PurchasedViewController *purchaseContr = (PurchasedViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"menu"];
//menu is only an example
purchaseContr.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:purchaseContr animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

我在我的剧本中使用命令模块,它目前看起来像这样。
- hosts: all
tasks:
- name: Update tar file
command: sudo scp -r username@hostname:/path/from/destination /path/to/destination
Run Code Online (Sandbox Code Playgroud)
出于可读性的目的,我省略了在此任务之前发生的任务,但是当我运行此 playbook 时,它会在此任务处停止。它根本不会前进。我确定这是因为 sudo,所以它可能需要密码。但是,我不确定如何解决这个问题。
如何从python中调用包含regexp(即cat filename*)的shell命令.
我写:
pid = subprocess.Popen(["cat", filename + "*"])
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个错误
cat filename*没有这样的文件或目录.
我想强制shell将"*"视为正则表达式而不是字符串.有没有办法实现这个?
我遇到过这个问题,我无法理解为什么.
我从我的应用程序中获取了我的代码,并制作了这个测试代码,这样你就不必经历一堆垃圾,看看我在问什么.
我有其他代码工作.但经过比较两者,我不能为我的生活弄清楚这一点.
在这个应用程序中,我得到错误"AttributeError:'NoneType'对象没有属性'删除'".
import Tkinter as tk
def main():
mainWindow = tk.Tk()
v = tk.StringVar()
entryBox = tk.Entry(mainWindow, textvariable=v).grid(column=0, row=1)
def test():
entryBox.delete(0,20)
testButton = tk.Button(mainWindow, text='Go!', command=test, padx=10).grid(row=2, column=0)
tk.mainloop()
main()
Run Code Online (Sandbox Code Playgroud) 我有一个名为"poc.py"的脚本,它带有一个位置命令行参数"inputfile.txt".poc.py脚本用于argparse处理位置命令行参数,然后将args dict传递给main().进入后main(),我读取输入文件,进行一些处理,创建一个pandas DataFrame,最后绘制数据.我很难操纵我的DataFrame并控制结果图的确切格式,所以我想尝试ipython以交互方式探索这个,看看我是否能更好地掌握处理pandas/matplotlib的"pythonic"方法.
所以我尝试使用ipython并运行脚本,但是我无法让ipython保留我的脚本命名空间.
我试过这个:
$ ipython --pylab -i poc.py inputfile.txt
Run Code Online (Sandbox Code Playgroud)
哪个运行我的脚本就好了,并显示图(即使没有阻塞plt.show()调用),但是当脚本完成时,ipython who和whos命令说Interactive namespace is empty.同样,如果我首先进入ipython shell然后执行:
In [2]: run poc.py inputfile.txt
Run Code Online (Sandbox Code Playgroud)
当脚本完成时(再次,大量输出,图表显示)我得到相同的结果:一个空的交互式命名空间.
在理解如何运行外部并使用ipython以交互方式探索脚本中的数据/对象方面,我缺少什么?
这是我的脚本(poc.py)设置方式的准系统示例:
import numpy as np
import matplotlib as plt
import pandas as pd
# etc ...more libraries and custom functions here...
def main(args):
data = np.genfromtxt(args.inputfile)
# (omitted)...more data processing / manipulation...
pdata = pd.DataFrame(data)
# (omitted)...more data …Run Code Online (Sandbox Code Playgroud) 我有用于反转字符串的代码.假设我键入'ABC',输出将为'CBA'.但是,有些代码行我完全不明白.
1 #include <stdio.h>
2 #include <string.h>
3
4 void print_reverse(char *s) {
5 size_t len = strlen(s);
6
7 char *t = s + len-1;
8 while(t >= s) {
9 printf("%c", *t);
10 t = t-1;
11 }
12 puts("");
13 }
14
15 int main()
16 {
17 char charinput[100];
18 printf("Enter character you want to reverse:");
19 fgets(charinput, 100, stdin);
20 print_reverse(charinput);
21 getchar();
22 }
Run Code Online (Sandbox Code Playgroud)
第7行和第8行有什么作用?指针t的输出是什么?
我想知道您是否可以轻松地添加最小值(如果该值为 0.0 ... 0.9,则应默认为 1:
-Xmx{{(some_variable*0.666)|int }}m
Run Code Online (Sandbox Code Playgroud)