我用matplotlib在图上绘制线条.现在我想为线上的各个点设置样式,特别是标记.我该怎么做呢?
编辑:澄清我的问题,已经回答,我希望能够在一条线上设置单个标记的样式,而不是在所述行上的每个标记.
我在Python中使用SQLAlchemy,我想知道如何获取列中的总行数.我定义了变量:
engine = sqlalchemy.create_engine(url, ehco=False)
Session = sqlalchemy.orm.sessionmaker(bind=engine)
Session = session()
metadata = sqlalchemy.MetaData(engine)
Base = declarative_base(metadata=metadata)
# A class representing the shape_congress_districts_2012 table
class Congress(Base):
__tablename__ = 'shape_congress_districts_2012'
id = geoalchemy.Column(sqlalchemy.Integer, primary_key=True)
name = geoalchemy.Column(sqlalchemy.Unicode)
geom = geoalchemy.GeometryColumn(geoalchemy.Polygon(2))
geom_simple = geoalchemy.GeometryColumn(geoalchemy.Polygon(2))
area = geoalchemy.Column(sqlalchemy.Float)
state_id = geoalchemy.Column(sqlalchemy.Integer)
census_year = geoalchemy.Column(sqlalchemy.Date)
geoalchemy.GeometryDDL(Congress.__table__)
Run Code Online (Sandbox Code Playgroud)
我想确定表中的总行数,而不必等待一大堆时间查询数据库.目前,我有一些代码:
rows = session.query(Congress).all()
Run Code Online (Sandbox Code Playgroud)
然后我可以从列表中访问它们,但这需要我立即将所有内容加载到内存中.
我试图在Apple脚本中嵌入AppleScript.我不想将AppleScript保存为文件,然后将其加载到我的Python脚本中.有没有办法在Apple中将AppleScript作为字符串输入并让Python执行AppleScript?谢谢一堆.
这是我的脚本:import subprocess import re import os
def get_window_title():
cmd = """osascript<<END
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application frontApp
if the (count of windows) is not 0 then
set window_name to name of front window
end if
end tell
return window_name
END"""
p = subprocess.Popen(cmd, shell=True)
p.terminate()
return p
def get_class_name(input_str):
re_expression = re.compile(r"(\w+)\.java")
full_match = re_expression.search(input_str)
class_name = full_match.group(1)
return class_name
print get_window_title()
Run Code Online (Sandbox Code Playgroud) 我正在学习编程语言的课程,"什么时候是一个函数是另一个函数的子类型"的答案对我来说非常反直觉.
澄清一下:假设我们有以下类型关系:
bool<int<real
Run Code Online (Sandbox Code Playgroud)
为什么函数(real->bool)是子类型(int->bool?不应该是相反的方式吗?
我希望子类型函数的标准是:如果f2可以采用f1可以采用的任何参数,则f1是f2的子类型,并且f1仅返回f2返回的值.显然有f1可以采用的值,但f2不能.
是否可以在SML中编写递归匿名函数?我知道我可以使用fun语法,但我很好奇.
我写过,作为我想要的一个例子:
val fact =
fn n => case n of
0 => 1
| x => x * fact (n - 1)
Run Code Online (Sandbox Code Playgroud) 我正在学习我的方式,我对语言的构建方式特别感兴趣.我试图找到一个很好的描述Scheme实现的核心语法.我对标准知之甚少,但我认为它们都包含宏系统.如果没有,我想阅读一个包含宏的标准(它们不可能在更简单的Scheme结构中实现,可以吗?).
有没有人对Scheme方言所需的最小语法有很好的参考?
只是一个更新:
我也偶然发现了这个问题:http://matt.might.net/articles/compiling-to-java/#sec1.如果你也添加define-syntax,delay那么它似乎是一个良好的开端.
在R5RS规范中,以下页面似乎是我正在寻找的:正式语法
目前我有一个通用函数,你可以传入一个属性名和一个类(它也适用于特定的对象实例,但我正在使用类),该函数将通过调用查找并操作该属性
getattr(model_class, model_attribute)
Run Code Online (Sandbox Code Playgroud)
它将通过调用(此时在对象实例上)来修改属性
settattr(model_obj,key,value)
但是,我有一个类,我们有一个@property方法定义而不是一个简单的属性,并setattr不起作用.如何@property基于该属性方法的字符串名称动态获取?
也许我可以使用,__dict__但这看起来很脏而且不那么安全.
编辑:示例代码
广义函数
def process_general(mapping, map_keys, model_class, filter_fn, op_mode=op_modes.UPDATE):
"""
Creates or updates a general table object based on a config dictionary.
`mapping`: a configuration dictionary, specifying info about the table row value
`map_keys`: keys in the mapping that we use for the ORM object
`model_class`: the ORM model class we use the config data in
`op_mode`: the kind of operation we want to perform (delete, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Clojure中创建一个函数,它是(let ...)函数体的本地函数.我尝试了以下内容,但(defn ...)定义了全局命名空间中的内容.
(let [] (defn power [base exp]
(if (= exp 0)
1
(if (> exp 0)
; Exponent greater than 0
(* base (power base (- exp 1)))
; Exponent less than 0
(/ (power base (+ exp 1)) base))))
(println (power -2 3)))
; Function call outside of let body
(println (power -2 3))
Run Code Online (Sandbox Code Playgroud)
现在,我也尝试过:
(let [power (fn [base exp]
(if (= exp 0)
1
(if (> exp 0)
; Exponent greater than 0
(* base (power …Run Code Online (Sandbox Code Playgroud) 我正在使用Mac OS X,我正在尝试从Mono Basics网站运行以下代码:
using Gtk;
using System;
class Hello {
static void Main()
{
Application.Init ();
Window window = new Window ("helloworld");
window.Show();
Application.Run ();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我用以下命令编译:
gmcs hellogtk.cs -pkg:gtk-sharp-2.0
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Package gtk-sharp-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk-sharp-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk-sharp-2.0' found
error CS8027: Error running pkg-config. Check the above output.
Run Code Online (Sandbox Code Playgroud)
我不知道软件包目录在我的计算机上的位置,所以我不知道将PKG_CONFIG_PATH设置为什么.你们有没有人在Mac OS X上使用Mono,你能指出我正确的方向,这些文件在哪里以及我应该将PKG_CONFIG_PATH设置为什么?
我在require使用Racket时正在尝试使用另一个文件.我在同一个文件夹中有两个文件.他们是world.rkt和ant.rkt.
world.rkt:
(module world racket
(provide gen-grid gen-cell)
(define (gen-cell item fill)
(cons item fill))
(define (gen-grid x y fill)
(begin
(define (gen-row x fill)
(cond ((> x 0) (cons (gen-cell (quote none) fill)
(gen-row (- x 1) fill)))
((<= x 0) (quote ()) )))
(cond ((> y 0) (cons (gen-row x fill)
(gen-grid x (- y 1) fill)))
((<= y 0) (quote ()) )))))
Run Code Online (Sandbox Code Playgroud)
ant.rkt:
(module ant racket
(require "world.rkt")
(define …Run Code Online (Sandbox Code Playgroud) python ×4
macos ×2
recursion ×2
scheme ×2
applescript ×1
attributes ×1
clojure ×1
descriptor ×1
lisp ×1
matplotlib ×1
module ×1
mono ×1
numpy ×1
path ×1
racket ×1
sml ×1
sql ×1
sqlalchemy ×1
syntax ×1
type-theory ×1
types ×1