程序设计

专业和发烧友程序员的问答

6
如何告诉matplotlib我已经完成了情节?
下面的代码绘制到两个PostScript(.ps)文件,但是第二个包含这两行。 import matplotlib import matplotlib.pyplot as plt import matplotlib.mlab as mlab plt.subplot(111) x = [1,10] y = [30, 1000] plt.loglog(x, y, basex=10, basey=10, ls="-") plt.savefig("first.ps") plt.subplot(111) x = [10,100] y = [10, 10000] plt.loglog(x, y, basex=10, basey=10, ls="-") plt.savefig("second.ps") 如何告诉matplotlib重新开始第二个绘图?
165 python  matplotlib  plot 


6
C#枚举中的方法
在Java中,可以在枚举内包含方法。 C#中是否存在这种可能性,或者仅仅是字符串集合而已? 我试图覆盖,ToString()但它不能编译。有人有一个简单的代码示例吗?
165 c#  enums  enumeration 

6
Go中的零检测
我在Go中看到很多检测nil的代码,如下所示: if err != nil { // handle the error } 但是,我有一个这样的结构: type Config struct { host string port float64 } 而config是Config的实例,当我这样做时: if config == nil { } 有编译错误,说:无法将nil转换为Config类型
165 go  null 

7
在postgres中选择字段的数据类型
如何从Postgres中的表中获取特定字段的数据类型?例如,我有下表,student_details(stu_id整数,stu_name varchar(30),joind_date时间戳); 在使用字段名称/或任何其他方式时,我需要获取特定字段的数据类型。有没有可能?
165 postgresql 

5
为什么React 16中的片段比容器div更好?
在React 16.2中,增加了对的支持Fragments。可以在React的博客文章中找到更多信息。 我们都熟悉以下代码: render() { return ( // Extraneous div element :( <div> Some text. <h2>A heading</h2> More text. <h2>Another heading</h2> Even more text. </div> ); } 是的,我们需要一个容器div,但这没什么大不了的。 在React 16.2中,我们可以这样做以避免周围的容器div: render() { return ( <Fragment> Some text. <h2>A heading</h2> More text. <h2>Another heading</h2> Even more text. </Fragment> ); } 无论哪种情况,我们仍然需要围绕内部元素的容器元素。 …
165 reactjs 

19
无法在“ DOMWindow”上执行“ postMessage”:https://www.youtube.com!== http:// localhost:9000
这是我收到的错误消息: Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://www.youtube.com') does not match the recipient window's origin ('http://localhost:9000'). 我还看到了其他类似的问题,其中目标的原点是http://www.youtube.com和接收者的原点是https://www.youtube.com,而我的目标https://www.youtube.com和目标的原点是http://localhost:9000。 我没问题。问题是什么? 我该如何解决?

7
如何使方法的返回类型通用?
有没有办法使此方法通用,以便我可以返回字符串,bool,int或double?现在,它正在返回一个字符串,但是如果它能够找到“ true”或“ false”作为配置值,那么我想返回一个布尔值。 public static string ConfigSetting(string settingName) { return ConfigurationManager.AppSettings[settingName]; }
165 c#  .net  generics  return-type 


2
argparse模块如何添加不带任何参数的选项?
我使用创建了一个脚本argparse。 脚本需要使用配置文件名作为选项,用户可以指定是完全执行脚本还是仅模拟脚本。 要传递的args:./script -f config_file -s或./script -f config_file。 -f config_file部分可以,但是它一直在询问我-s的参数,该参数是可选的,不应跟随任何参数。 我已经试过了: parser = argparse.ArgumentParser() parser.add_argument('-f', '--file') #parser.add_argument('-s', '--simulate', nargs = '0') args = parser.parse_args() if args.file: config_file = args.file if args.set_in_prod: simulate = True else: pass 有以下错误: File "/usr/local/lib/python2.6/dist-packages/argparse.py", line 2169, in _get_nargs_pattern nargs_pattern = '(-*%s-*)' % '-*'.join('A' * nargs) …
165 python  argparse 

15
如何在macOS上将Git升级到最新版本?
我刚刚购买了带有OS X Lion的新Mac,并在终端中检查了默认情况下安装的git版本。我得到了答案 git --version > git version 1.7.5.4 我想将git升级到最新版本1.7.8.3,因此我下载了dmg安装程序“ git-1.7.8.3-intel-universal-snow-leopard.dmg”,并启动了它。 安装后,终端仍然会说版本是1.7.5.4。我究竟做错了什么?
165 macos  git 

15
如何测试双精度数是否为整数
是否有可能做到这一点? double variable; variable = 5; /* the below should return true, since 5 is an int. if variable were to equal 5.7, then it would return false. */ if(variable == int) { //do stuff } 我知道代码可能不会去这样的事情,但怎么也去了?
165 java  math 

4
在Docker Alpine容器中启动Shell
要为Ubuntu映像启动交互式shell,我们可以运行: ole@T:~$ docker run -it --rm ubuntu root@1a6721e1fb64:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var 但是,对于Alpine Docker映像运行此命令时,将得到以下结果: ole@T:~$ docker run -it --rm alpine Error response from daemon: No command specified 在Alpine基本容器中启动交互式Shell的命令是什么?



By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.