小编Kal*_*_89的帖子

使用Excel宏(ADODB)在SQL Server 2008中创建临时表

经过大量的谷歌搜索,我最终得到了以下宏,我希望连接到数据库,删除任何现有的临时表,然后创建一个新的(填充它,并查看结果).

Dim adoCn As ADODB.Connection
Dim adoRs As ADODB.Recordset
Dim adoCm As ADODB.Command
Dim strSQL As String

Set adoCn = New ADODB.Connection
With adoCn
    .ConnectionString = "Provider=SQLOLEDB;" & _
                        "Initial_Catalog=XXX;" & _
                        "Integrated Security=SSPI;" & _
                        "Persist Security Info=True;" & _
                        "Data Source=XXX;" & _
                        "Extended Properties='IMEX=1'"
    .CursorLocation = adUseServer
    .Open
End With

Set adoCm = New ADODB.Command

With adoCm
    Set .ActiveConnection = adoCn
    .CommandType = adCmdText
    .CommandText = "IF OBJECT_ID('tempdb..#AgedProducts') IS NOT NULL DROP TABLE #AgedProducts"
    .Execute
    .CommandText = …
Run Code Online (Sandbox Code Playgroud)

sql excel vba excel-vba sql-server-2008

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

没有路线匹配 - Rails

在 Rails 中设置我的第二个项目(首先不遵循教程)并且遇到了我无法用我的路线解决的问题。一切都像我希望的那样与我的 routes.rb 文件一样:

AnimalApp::Application.routes.draw do

    root to: 'static_pages#index'
        # resources :animal
    match '/help', to: 'static_pages#help'
    match '/about', to: 'static_pages#about'
    match '/contact', to: 'static_pages#contact'
    match '/league', to: 'static_pages#league'
    match '/animal', to: 'animal#new'
Run Code Online (Sandbox Code Playgroud)

除了我不能接触我的动物!转到 /animal/1 会引发错误: No route matches [GET] "/animal/1"

为了解决这个问题,我改变了我的路线如下:

    AnimalApp::Application.routes.draw do

    root to: 'static_pages#index'
        resources :animal
    match '/help', to: 'static_pages#help'
    match '/about', to: 'static_pages#about'
    match '/contact', to: 'static_pages#contact'
    match '/league', to: 'static_pages#league'
    #match '/animal', to: 'animal#new'
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试查看我网站上的任何其他页面时,出现以下错误: No route matches {:action=>"show", :controller=>"animal"}

有关更多信息,请参阅下面我的控制器:(静态页面)

class StaticPagesController < ApplicationController …
Run Code Online (Sandbox Code Playgroud)

ruby routes ruby-on-rails ruby-on-rails-3.2

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

给出列表生成Python字典的最有效方法

我正在寻找以下问题的优化(我有一些工作代码,但我很确定它可能会更快,写得很糟糕).我有一个SKU列表(6到9位数字),我正在亚马逊上查找信息.工作代码如下:

def buildDictionary2(stringy):
    x = stringy.xpath('//sellersku/text()|//product/descendant::amount[1]/text()')
    Sku_To_Price = {}
    for items in range(len(x)):
        if x[items] in myList:
            try:
                if x[items+1] not in myList:
                    Sku_To_Price[x[items]] = x[items+1]
                else:
                    Sku_To_Price[x[items]] = ''
            except:
                pass
        else:
            pass
    return Sku_To_Price
Run Code Online (Sandbox Code Playgroud)

其中x是一般交替的SKU和价格的字典.但是,由于无法找到价格,因此出现了复杂情况.在这种情况下,列表(x)是SKU,SKU而不是SKU价格.

目前我正在查找SKU列表(在全局变量myList中),但无法帮助实现时间复杂度O(e ^ n).鉴于我正在寻找20,000个SKU区域的工作,我宁愿不是这样.

有没有办法使这个不那么复杂 - 所需的输出是一个字典,每个SKU一次(作为一个键),它的相应价格作为价值(如果没有价格,没有条目).

编辑:

正在解析的XML示例

<?xml version="1.0" ?>
<GetLowestOfferListingsForSKUResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
  <GetLowestOfferListingsForSKUResult SellerSKU="X" status="Success">
    <AllOfferListingsConsidered>true</AllOfferListingsConsidered>
    <Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" 
             xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
      <Identifiers>
        <MarketplaceASIN>
          <MarketplaceId>X</MarketplaceId>
          <ASIN>X</ASIN>
        </MarketplaceASIN>
        <SKUIdentifier>
          <MarketplaceId>X</MarketplaceId>
          <SellerId>X</SellerId>
          <SellerSKU>10065897</SellerSKU>
        </SKUIdentifier>
      </Identifiers>
      <LowestOfferListings>
        <LowestOfferListing>
          <Qualifiers>
            <ItemCondition>New</ItemCondition>
            <ItemSubcondition>New</ItemSubcondition>
            <FulfillmentChannel>Amazon</FulfillmentChannel>
            <ShipsDomestically>True</ShipsDomestically>
            <ShippingTime>
              <Max>X</Max>
            </ShippingTime>
            <SellerPositiveFeedbackRating>X</SellerPositiveFeedbackRating>
          </Qualifiers> …
Run Code Online (Sandbox Code Playgroud)

python optimization performance data-structures

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

冻结Ruby中的随机数

我正在尝试构建一些东西,它将从Ruby中的列表中随机选择两个对象(使用Rails),然后对这些对象执行基本操作.我当前的设置包括在开始时随机选择数字 - 使用这些数字从数据库中获取对象,然后将这些对象呈现为索引.但是,现在我正在尝试使用AJAX编辑这些对象我遇到了问题.

看来,当我点击链接时,重新计算的随机数会导致我的AJAX功能不起作用.

我已经包含了(我相信的)以下所有相关代码,但如果您需要查看其他任何内容,请告知我们.我希望得到旧动物的标题和(理想情况下他们之前的评级和)他们的新评级出现在页面底部.

谢谢,

马特

controllers/static_pages.rb

class StaticPagesController < ApplicationController
respond_to :html, :js
before_filter :pickanimals

def pickanimals
    @allAnimals = Animal.all
    @random_no = rand(@allAnimals.length)
    @animal = @allAnimals[@random_no]
    @allAnimals.delete_at(@random_no)
    @newRandom = rand(@allAnimals.length)
    @animal2 = @allAnimals[@newRandom]
end

  def index
    respond_to do |format|
        format.html
        format.js
    end
end

  def help
  end

  def about
  end

  def contact
  end

def league
end

def voting
    @votedAnimal = Animal.find(params[:id])
    if @votedAnimal == @animal
        @animal.rating += 1
        @animal2.rating -= 1
    else
        @animal.rating -= 1
        @animal2.rating += 1    
    end …
Run Code Online (Sandbox Code Playgroud)

ruby random ajax ruby-on-rails ruby-on-rails-3

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

以pythonic方式从制表符分隔文件构建字典

我编写了以下函数,该函数采用制表符分隔文件(作为字符串)并将其转换为字典,其中包含整数作为键和两个浮点数的列表以及值:

def parseResults(self, results):
    """
    Build a dictionary of the SKU (as key), current UK price and current Euro price
    """
    lines = results.split('\n')
    individual_results = []
    for i in range(1,len(lines)-1):
        individual_results.append(lines[i].split('\t'))
    results_dictionary = {}
    for i in range(len(individual_results)):
        results_dictionary[int(individual_results[i][0])] = [float(individual_results[i][1]), float(individual_results[i][2])]
    return results_dictionary
Run Code Online (Sandbox Code Playgroud)

我一直在阅读有关使用列表理解和字典理解的内容,但我真的不知道构建它的最佳方法是什么.

我想我可以使用以下方法简化第一个列表构建:

individual_results = [results.split('\t') for results in lines[1:]]
Run Code Online (Sandbox Code Playgroud)

但我不知道创建字典的最佳方法.我甚至没有创建中间列表,我觉得这可能是一种整洁的方式.

谢谢,

马特

python dictionary list python-2.7

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