小编Kra*_*mar的帖子

如何粘贴到终端?

我复制了一个URL,例如git://gitorious.org/openhatch/oh-mainline.git.我想使用键盘快捷键将其粘贴到终端中.

不要说"右击并粘贴".

linux terminal command

77
推荐指数
5
解决办法
20万
查看次数

如何获取jinja 2模板中所有变量的列表

我试图获取模板中所有变量和块的列表.我不想创建自己的解析器来查找变量.我尝试使用以下代码段.

from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('gummi', 'templates'))
template = env.get_template('chat.html')
Run Code Online (Sandbox Code Playgroud)

template.blocks 是键是块的dict,如何获取块内的所有变量?

jinja2

27
推荐指数
4
解决办法
2万
查看次数

sys和os.sys有什么区别

sysos.syspython有什么区别?我看到许多项目sys在导入时使用os.当我尝试dir(sys)并且dir(os.sys)它们具有相同的功能并且它们的输出相同时.

我经常看到代码使用sys.exit这样,而不是使用os.sys.exit,但两者都做同样的事情.

import os   
import sys    
sys.exit()
Run Code Online (Sandbox Code Playgroud)

python

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

使用alembic获取表值并更新到另一个表.

我有oauth secretoauth keyclient表中.现在我将它们移动到oauth credentials将在迁移期间创建的表.Alembic生成以下架构进行升级.

from myapp.models import Client, ClientCredential
from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
    op.create_table('client_credential',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('client_id', sa.Integer(), nullable=False),
    sa.Column('key', sa.String(length=22), nullable=False),
    sa.Column('secret', sa.String(length=44), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.ForeignKeyConstraint(['client_id'], ['client.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('key')
   )
   # Here I need to copy data from table A to newly created Table.
   # …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy alembic

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

LMS in Python/Django/Ruby/Rails/PHP

我正在寻找替代方案Moodle.
我搜索并发现pinax-lms-demo,这是基于Django的;
Astra这是基于Rails的,但两者都是空的回购...

我需要一个具有以下功能的LMS:

  1. 创造阶级
  2. 分配教师
  3. 上传资料
  4. 参加测验
  5. 论坛
  6. SCORM

我花了一个多月的时间使用Moodle并成为开发人员,我觉得我不应该使用它...

php python django ruby-on-rails

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

并行性不会减少数据集映射的时间

TF Map功能支持并行调用.我看到没有改进传递num_parallel_calls给地图.使用num_parallel_calls=1num_parallel_calls=10,性能运行时间没有改善.这是一个简单的代码

import time
def test_two_custom_function_parallelism(num_parallel_calls=1, batch=False, 
    batch_size=1, repeat=1, num_iterations=10):
    tf.reset_default_graph()
    start = time.time()
    dataset_x = tf.data.Dataset.range(1000).map(lambda x: tf.py_func(
        squarer, [x], [tf.int64]), 
        num_parallel_calls=num_parallel_calls).repeat(repeat)
    if batch:
        dataset_x = dataset_x.batch(batch_size)
    dataset_y = tf.data.Dataset.range(1000).map(lambda x: tf.py_func(
       squarer, [x], [tf.int64]), num_parallel_calls=num_parallel_calls).repeat(repeat)
    if batch:
        dataset_y = dataset_x.batch(batch_size)
        X = dataset_x.make_one_shot_iterator().get_next()
        Y = dataset_x.make_one_shot_iterator().get_next()

    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        i = 0
        while True:
            try:
                res = sess.run([X, Y])
                i += 1
                if i == num_iterations:
                    break
            except tf.errors.OutOfRangeError …
Run Code Online (Sandbox Code Playgroud)

tensorflow tensorflow-datasets

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

在rails中创建一个表并添加外键约束

我有一个表students与现场ward_id,我必须创建一个名为表guardian_users与领域id,ward_id,email,guardian_id,hashed_password等.

现在我必须添加约束foreign key.学生中的任何更新/删除/编辑/插入都应对guardian_users产生相同的影响.

我怎么能在rails 2.3.5中做到这一点?

表学生存在但其他人尚不存在.

ruby activerecord ruby-on-rails

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

在多重继承中访问超类方法的更好方法

class Animal(object):
    def eat(self):
        print("I eat all")

class C(object):
    def eat(self):
        print("I too eat")

class Wolf(C, Animal):
    def eat(self):
        print("I am Non Veg")
        super(Wolf, self).eat()
        Animal.eat(self)

w = Wolf()
w.eat()
Run Code Online (Sandbox Code Playgroud)

我正在学习python中的多重继承,我想使用方法从派生类访问Animal和方法.Ceatsuper

super内部调用C 类方法的默认调用eat,但调用Animal我使用的类方法.Animal.eat(self)我的问题是如何Animal使用super方法调用类方法.

python

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

Python mypy无法从union返回类型推断出类型

这是示例代码

from typing import Dict, Union, Tuple


def select_range(data: Dict[str, Union[str, int]]) -> Tuple[int, int]:
    if data['start'] and data['end']:
        return data['start'], data['end']
    return 1, 1

select_range({})
Run Code Online (Sandbox Code Playgroud)

Mypy输出:

mypy different_return.py
different_return.py:6: error: Incompatible return value type (got 
"Tuple[Union[str, int], Union[str, int]]", expected "Tuple[int, int]")
Run Code Online (Sandbox Code Playgroud)

即使其中一个字典值是int,mypy也无法推断出这一点.

python static-typing mypy

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

Ruby on rails上的捆绑错误

我在一个ror项目中运行bundle,导致跟随错误.

我无法理解缺少的东西.

[root@kracekumar canvas-lms]# bundle
Fetching source index for http://rubygems.org/
Using rake (0.8.7) 
Using abstract (1.0.0) 
Installing activesupport (2.3.11) 
Using rack (1.1.0) 
Installing actionpack (2.3.11) 
Installing actionmailer (2.3.11) 
Installing activerecord (2.3.11) 
Installing activeresource (2.3.11) 
Installing authlogic (2.1.3) 
Using builder (2.1.2) 
Using mime-types (1.16) 
Installing xml-simple (1.0.12) 
Installing aws-s3 (0.6.2) 
Installing bluecloth (2.0.10) with native extensions 
/usr/lib/ruby/site_ruby/1.8/rubygems/installer.rb:481:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/usr/bin/ruby extconf.rb 
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h


Gem files will remain …

ruby-on-rails

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

Rails不呈现部分(_new_multiple_choice.rjs)

#online_exam_controller
class OnlineExamController < ApplicationController
   def index
    @user=current_user
    @employee=Employee.find_by_employee_number(@user.username)
    # flash[:notice]="#{@employee.id}"
    @subjects=EmployeesSubject.find_all_by_employee_id(@employee.id)
    @subject_name=[]
    @batch_details=[]
    @display_details=[[]]
    @count=0
    for @t in @subjects
     @subject_name[@count]=Subject.find(@t.subject_id,:select=>'name,code,batch_id')
     @batch_details[@count]=Batch.find(@subject_name[@count].batch_id,:select =>'name')
     @display_details[@count][0]=@subject_name[@count].name+" "+@batch_details[@count].name
     @display_details[@count][1]=@t.subject_id
     @count+=1
    end
   end
   def show
    if params[:subject_id]==''
     @question_type=[]
    else
     @question_type=['multiple_choice','fill_ups','matches','descriptive']
     @subject_id=params[:subject_id]

   end
   respond_to do |format|
   format.js {render:action=>'show' }
   end
  end
  def new_multiple_choice
   @quiz=MultipleChoiceQuestion.new
   @subject=Subject.find params[:id] if request.xhr? and params[:id]
   respond_to do |format|
    format.js {render :action => 'new_multiple_choice'}
   end
  end
 end
#index.html.erb
<div id="content-header">
<img src="/images/show_settings.png" alt="Subjects"/>
<h1>Subjects</h1>
<h3>Home</h3>
 <div id="app-back-button">
 <%= link_to_function image_tag("/images/buttons/back.png",:border => …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rjs

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