小编RyP*_*eck的帖子

为什么在Python格式的迷你语言的所有例子中都有':'?

我在看这个具体的例子:

x = 3.45678
print({':.2f'}.format(x))
Run Code Online (Sandbox Code Playgroud)

我不能为我的生活找到任何涉及冒号的文件. http://docs.python.org/2/library/string.html#grammar-token-precision

如果有人能够指出我自己能够学到的东西,我真的更喜欢.

python string-formatting

3
推荐指数
1
解决办法
909
查看次数

如何在ggplot2 geom_boxplot中使用实心方块作为图例键

我正在尝试使用 R ggplot2包来制作箱线图。

但是我只能得到这样的传说。无论如何我可以将那些图例键更改为一个实心方块,而不是使用那些带有中心线的小盒子?

我使用的代码是:

print(ggplot(mydata,aes(x=factor(sp),fill=factor(CommunityType),y=Abundance*100))+geom_boxplot(show_guide=FALSE)
      +theme(axis.text = element_text(colour = "black",size=10))
      +scale_y_continuous(" RA (%) ")+scale_x_discrete(limits=taxalist[1:5]," ")
      +scale_fill_manual(name = "MY type", values = mycol[1:nmc])
      +theme_bw() + guides(fill=guide_legend(title=NULL))+theme(legend.position=c(1,1),legend.justification=c(1,1)) 
      +theme(legend.key = element_blank(),legend.key.size = unit(1.5, "lines"))
      +theme( panel.grid.major = element_blank(),  panel.grid.minor = element_blank(),  panel.background = element_blank())  )
Run Code Online (Sandbox Code Playgroud)

抱歉,我无法在这里形象地描述我的问题。

r legend ggplot2 boxplot

2
推荐指数
1
解决办法
3110
查看次数

正则表达式匹配一个单词和之后的一切?

我需要将一些http数据作为一个字符串从一个字符串格式的字符串中转储,我试图使用下面的正则表达式来匹配'data:'以及它之后的所有内容,它不起作用.我是regex和python的新手

>>>import re
>>>pat=re.compile(r'(?:/bdata:/b)?\w$')
>>>string=" dnfhndkn data: ndknfdjoj pop"
>>>res=re.match(pat,string)
>>>print res
   None
Run Code Online (Sandbox Code Playgroud)

python regex

2
推荐指数
2
解决办法
6799
查看次数

AWS Lambda Python 3 检查事件变量存在

 try: 
        event['ids']
 except NameError: 
        ids = None
Run Code Online (Sandbox Code Playgroud)

这是抛出一个KeyError。我只想检查事件变量是否存在并设置为 none 或如果存在则传递值。我也尝试使用

if (len(event['ids']) < 1) 
Run Code Online (Sandbox Code Playgroud)

但得到一个错误。我错过了什么吗?我可能会也可能不会通过我的所有事件键并想要检查是否存在。

amazon-web-services python-3.x aws-lambda

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

Python:对数组进行排序

我有一个类,其唯一目的是对作为参数给出的数组进行排序,但首先,我得到一个错误"int not iterable".我的问题是这个错误是什么,我正在进行正确的排序吗?谢谢.这是我的分拣机类,由下面的其他类调用.

class Sorter:
    def reverseWackySort(self, vals):
        i = 0
        j = 0
        temp = 0
        length = len(vals)
        for i in length:
            for j in (length -1):
                if vals[j] > vals[j+1]:
                    temp = vals[j]
                    vals[j] = vals[j+1]
                    vals[j+1] = temp;
        return vals
Run Code Online (Sandbox Code Playgroud)

代码 -

from Sorter import Sorter

def TestSorter():
    rws = Sorter()


    nums = [88, 1, 7, 32, 18, 77, 34, 99, 54, 22]

    print "\nBefore Sort: ", nums

    rws.reverseWackySort(nums)

    print "After Sort:   {}\n".format(nums)

TestSorter()
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
246
查看次数

Python程序决策控制问题

我正在尝试创建一个代码库,我可以在其中存储随着时间的推移找到的代码片段并检索它们.到目前为止,这是我的代码.

# Python Code Library User Interface

import sys

class CodeLib:
    codes = []
    option = ['help (-h)', 'list (-l)', 'import (-i)', 'quit (-q)']

#What does the user want to do?
    print "Welcome to the Code Library"
    print "What would you like to do? \n %s" % option
    choice = raw_input()
    print choice
    if choice == 'quit' or '-q':
        sys.exit()
    length = len(choice)
# Getting name of file to import if user chooses import before
# viewing the code list …
Run Code Online (Sandbox Code Playgroud)

python if-statement

-1
推荐指数
1
解决办法
114
查看次数

Python:无法在列表末尾添加字符串

我正在尝试制作基于文本的RPG,当我试图将每个可能的输入缩短为一个变量时,我无法用字符串结束列表:

input_use = ["use ", "use the "]
...
input_press = ["press ", "press the ", input_use]
...
input_interact_button = input_press + "button"
Run Code Online (Sandbox Code Playgroud)

python string list

-2
推荐指数
1
解决办法
2314
查看次数

C中的程序正确启动但printf没有显示任何内容

我运行程序和控制台出现但printf没有打印任何东西,我该如何解决这个问题?

#include<stdio.h>
main()
{
    float fa;
    int cel;
    cel=0;
    while(cel<=200);
    {
        fa=9.000*(cel+32.000)/5.000;
        printf("%d\t%.3f\n",cel,fa);
        cel=cel+20;
    }
}
Run Code Online (Sandbox Code Playgroud)

另外我有一个非常相似的程序,可以正常运行

#include<stdio.h>
main()
{
  float celsius;
  int fahr;
  fahr = 0;
    while(fahr<=100){
    celsius=5.0000*(fahr-32.0000)/9.0000;
    printf("%d\t%.4f\n",fahr,celsius);
    fahr=fahr+1;
  }
}
Run Code Online (Sandbox Code Playgroud)

我用c-free 5运行了这两个程序

c

-3
推荐指数
1
解决办法
99
查看次数