Category Archives: How to Fix

In Python, print() prints to remove line breaks

python print() prints, the default is a newline.
for example:

print('abc')
pirnt('xyz')

gives us

abc
xyz

what do I do if I want to get , abcxyz, which is to print two lines and put them in one line.
can be used with the code:

print('abc',end='')
print('xyz')

so that the printed result does not have a line break:
abcxyz

before I saw someone on the Internet write this:

print('abc'),
print('xyz')

is comma separated, and this python3 is no longer valid. Python2 works fine. But there’s a space in between, and in python2 the printed result is: ABC xyz

Error resolution by Ubuntu: aclocal-1.14 ‘is missing on your system

http://blog.csdn.net/wwt18946637566/article/details/46602305

problem

we have a problem installing protobuf to make

CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash /home/user/protobuf-2.6.1/protobuf-2.6.1/missing aclocal-1.14 -I m4
/home/user/protobuf-2.6.1/protobuf-2.6.1/missing: line 81: aclocal-1.14: command not found
WARNING: 'aclocal-1.14' is missing on your system.
         You should only need it if you modified 'acinclude.m4' or
         'configure.ac' or m4 files included by 'configure.ac'.
         The 'aclocal' program is part of the GNU Automake package:
         <http://www.gnu.org/software/automake>
         It also requires GNU Autoconf, GNU m4 and Perl in order to run:
         <http://www.gnu.org/software/autoconf>
         <http://www.gnu.org/software/m4/>
         <http://www.perl.org/>
Makefile:641: recipe for target 'aclocal.m4' failed
make: *** [aclocal.m4] Error 127

solution

reference: http://blog.csdn.net/wwt18946637566/article/details/46602305

actually I used only one instruction
sudo autoreconf-ivf

Java uses regular expressions to intercept the contents between specified strings

Java USES regular expressions to intercept the contents between specified strings:

package com.accord.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式匹配两个字符串之间的内容
 * @author Administrator
 *
 */
public class RegexUtil {
	
	public static void main(String[] args) {
		String str = "<?xml version='1.0' encoding='UTF-8'?><ufinterface billtype='gl' filename='e:\1.xml' isexchange='Y' proc='add' receiver='1060337@1060337-003' replace='Y' roottag='sendresult' sender='01' successful='Y'><sendresult><billpk></billpk><bdocid>w764</bdocid><filename>e:\1.xml</filename><resultcode>1</resultcode><resultdescription>单据w764开始处理...单据w764处理完毕!</resultdescription><content>2017.09-记账凭证-1</content></sendresult><sendresult><billpk></billpk><bdocid>w1007</bdocid><filename>e:\1.xml</filename><resultcode>1</resultcode><resultdescription>单据w1007开始处理...单据w1007处理完毕!</resultdescription><content>2017.10-记账凭证-1</content></sendresult><sendresult><billpk></billpk><bdocid>w516</bdocid><filename>e:\1.xml</filename><resultcode>1</resultcode><resultdescription>单据w516开始处理...单据w516处理完毕!</resultdescription><content>2017.07-记账凭证-50</content></sendresult></ufinterface>";
		//String str = "abc3443abcfgjhgabcgfjabc";  
		String rgex = "<bdocid>(.*?)</bdocid>";
		
	    System.out.println((new RegexUtil()).getSubUtil(str,rgex)); 
	    List<String> lists = (new RegexUtil()).getSubUtil(str,rgex);
	    for (String string : lists) {
			System.out.println(string);
		}
	    System.out.println((new RegexUtil()).getSubUtilSimple(str, rgex));  
	}
	
	/** 
     * 正则表达式匹配两个指定字符串中间的内容 
     * @param soap 
     * @return 
     */  
    public List<String> getSubUtil(String soap,String rgex){  
        List<String> list = new ArrayList<String>();  
        Pattern pattern = Pattern.compile(rgex);// 匹配的模式  
        Matcher m = pattern.matcher(soap);  
        while (m.find()) {  
            int i = 1;  
            list.add(m.group(i));  
            i++;  
        }  
        return list;  
    }  
      
    /** 
     * 返回单个字符串,若匹配到多个的话就返回第一个,方法与getSubUtil一样 
     * @param soap 
     * @param rgex 
     * @return 
     */  
    public String getSubUtilSimple(String soap,String rgex){  
        Pattern pattern = Pattern.compile(rgex);// 匹配的模式  
        Matcher m = pattern.matcher(soap);  
        while(m.find()){  
            return m.group(1);  
        }  
        return "";  
    }  
}

operation results:

[w764, w1007, w516]
w764
w1007
w516
w764

ES6 determines what the string begins with or ends with

The

startsWith() method determines whether the string startsWith the character of the specified string and returns true or false. The
endsWith() method has the same syntax as the startsWith() method, except that the endsWith() method starts at the end of the string.

let str = "https://C:/Users/2/1.png";
console.log(str.startsWith("https://"))// true;
console.log(str.startsWith("http://"))// false;
console.log(str.endsWith(".jpg"))// false;
console.log(str.endsWith(".png"))// true;

JavaScript / JS native dynamic introduction of external CSS files and dynamic insertion of CSS code fragments

there are two ways to dynamically create CSS styles:
1. Introduce external CSS files
2. Insert CSS snippet
how to insert CSS external files dynamically:

function loadStyle(url){
var link = document.createElement('link');
    link.type = 'text/css';
    link.rel = 'stylesheet';
    link.href = url;
    var head = document.getElementsByTagName('head')[0];
    head.appendChild(link);
}
loadStyle('test.css');

dynamically loads CSS snippet

function loadCssCode(code){
    var style = document.createElement('style');
    style.type = 'text/css';
    style.rel = 'stylesheet';
    //for Chrome Firefox Opera Safari
    style.appendChild(document.createTextNode(code));
    //for IE
    //style.styleSheet.cssText = code;
    var head = document.getElementsByTagName('head')[0];
    head.appendChild(style);
}
loadCssCode('body{background-color:#f00}');

IE & lt; link> The tag is considered a special tag and its children cannot be accessed, so stylesheet.csstext is used, and errors thrown by IE are caught using a try catch statement, with the following compatible code:

function loadCssCode(code){
var style = document.createElement('style');
    style.type = 'text/css';
    style.rel = 'stylesheet';
    try{
        //for Chrome Firefox Opera Safari
        style .appendChild(document.createTextNode(code));
    }catch(ex){
        //for IE
        style.styleSheet.cssText = code;
    }
    var head = document.getElementsByTagName('head')[0];
    head.appendChild(style);
}
loadCssCode('body{background-color:#f00}');

adds styles to the page in real time, so you can react instantly on the page.

[Python] pandas Library pd.to_ Parameter arrangement and example of Excel operation writing into excel file

excel writes to pd. dataframe.to_excel (); Write DataFrame to an Excel sheet.

to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='', float_format=None,columns=None, 
header=True, index=True, index_label=None,startrow=0, startcol=0, engine=None, 
merge_cells=True, encoding=None,inf_rep='inf', verbose=True, freeze_panes=None)

common parameter resolution

  • excel_writer: ExcelWriter target path
In [16]: df = pd.read_csv('test.csv')

In [17]: df
Out[17]:
   index  a_name  b_name
0      0       1       3
1      1       2       3
2      2       3       4
#excel_writer :'excel_output.xls'输出路径
In [18]: df.to_excel('excel_output.xls')

Sheet_name: excel sheet name

#得到的表名就是'biubiu'
In [20]: df.to_excel('excel_output.xls',sheet_name='biubiu')
  • na_rep: missing value filled, can be set to the string
In [25]: df = pd.read_excel('excel_output.xls')

In [26]: df
Out[26]:
   index  a_name  b_name
0      0       1     3.0
1      1       2     3.0
2      2       3     NaN
#如果na_rep设置为bool值,则写入excel时改为01;也可以写入字符串或数字
In [27]: df.to_excel('excel_output.xls',na_rep=True)

In [28]: pd.read_excel('excel_output.xls')
Out[28]:
   index  a_name  b_name
0      0       1       3
1      1       2       3
2      2       3       1

In [29]: df.to_excel('excel_output.xls',na_rep=False)

In [30]: pd.read_excel('excel_output.xls')
Out[30]:
   index  a_name  b_name
0      0       1       3
1      1       2       3
2      2       3       0

In [31]: df.to_excel('excel_output.xls',na_rep=11)

In [32]: pd.read_excel('excel_output.xls')
Out[32]:
   index  a_name  b_name
0      0       1       3
1      1       2       3
2      2       3      11
  • columns: select the output columns to be stored.
In [44]: df.to_excel('excel_output.xls',na_rep=11,columns=['index'])

In [45]: pd.read_excel('excel_output.xls')
Out[45]:
   index
0      0
1      1
2      2
  • header: specify the row as the column name, default 0, that is, take the first row, the data is the data below the column name row; If the data does not contain column names, set header = None;
In [48]: df.to_excel('excel_output.xls',na_rep=11,index=False)

In [49]: pd.read_excel('excel_output.xls')
Out[49]:
   index  a_name  b_name
0      0       1       3
1      1       2       3
2      2       3      11

In [50]: df.to_excel('excel_output.xls',na_rep=11,index=False,header=None)

In [51]: pd.read_excel('excel_output.xls')
Out[51]:
   0  1   3
0  1  2   3
1  2  3  11
  • index: defaults to True and displays index. When index=False, row index (name) is not displayed
  • index_label: sets the column name of index column

Chrome browser forces page refresh (no caching)

in Chrome, pressing F5 or Ctrl+F5 doesn’t work. Chrome always forces page caches to refresh. How to refresh without page caches?

Chrome officially recommends the following shortcuts to refresh Windows and Linux operating systems without using the page cache: Shift+F5 or Ctrl+Shift+R
Mac OS: Cmd+Shft+R

if the above method doesn’t work, you can press F12(Windows) or Cmd+Opt+I(MAC), open “developer tools”, then right-click on the Refresh button and select “clear cache and load hardware” from the pop-up menu

welcome to my personal blog – bohan’s personal blog

The JSON object is converted into a formdata object, and the formdata object is converted into a JSON object

in the backward request, if there is a file object in the uploaded data, we need to use the form submission, at this time we need to convert the JSON object into a formData object, see the code

for details

  const formData = new FormData();
  Object.keys(params).forEach((key) => {
    formData.append(key, params[key]);
  });

may also require formData to be converted to JSON, the code is as follows:

  var jsonData = {};
  formData.forEach((value, key) => jsonData[key] = value);

A repeated string is composed of two identical strings. For example, abcabc is a repeated string with length of 6, while abcba does not have a duplicate string. Given any string, please help Xiaoqiang find the longest repeated substring.

a repeating string is a concatenation of two identical strings. For example, abcabc is a repeating string of length 6, while abcba does not have a repeating string.
given any string, find the longest repeating substring.

input description :

enter a string s, where s is less than 1e4 and contains only Numbers and letters.

output description :

outputs an integer representing the length of the longest repeating substring of s. If it does not exist, 0

is output

input example 1:

xabcabcx

output example 1:

6

def getMaxRepeatSubstringLength(inputStr):
    length = len(inputStr)
    for i in reversed(range(length//2)):
        count = 0
        for j in range(length - i):
            if inputStr[j] == inputStr[j+i]:
                count = count + 1
            else:
                if length - j <= 2 * i:
                    break
                count = 0
            if count == i:
                return count * 2
    return 0
inputStr = input()
print(getMaxRepeatSubstringLength(inputStr))

1. First assume the length of the longest repeating substring is I
2. Judge whether the length of the assumption is I is true
3. The longest repeating substring cannot be more than half of the total length
4. In the process of determining whether the hypothesis is true, if the remaining length to be determined is less than 2* I, the hypothesis must be false
5. Since it is the judgment of the eldest string, it is reasonable to assume that I is from large to small, and once it is met, you can withdraw directly. Whereas the assumption from small to large is to check all the cases.

Compare whether two sets are the same in Java

in Java API, it seems that there is no way to compare the contents of two sets, so we can only write one by ourselves to realize it. In fact, it is relatively simple to compare the number of records to see whether they are the same, and then see whether the contents are consistent. The test method is as follows:

public static boolean equals(Set<?> set1, Set<?> set2){
        if(set1 == null || set2 ==null){//null就直接不比了
            return false;
        }
        if(set1.size()!=set2.size()){//大小不同也不用比了
            return false;
        }
        return set1.containsAll(set2);//最后比containsAll
    }

unit test:

import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class TestSetUtils {
    @Test
    public void test1() {
        Set<String> test1 = new HashSet<>();
        test1.add("a");
        test1.add("b");
        Set<String> test2 = new HashSet<>();
        test2.add("b");
        test2.add("c");
        assertThat(SetUtils.equals(test1, test2), is(false));
    }
    @Test
    public void test2() {
        Set<String> test1 = new HashSet<>();
        test1.add("a");
        test1.add("b");
        Set<String> test2 = new HashSet<>();
        test2.add("a");
        test2.add("b");
        test2.add("c");
        assertThat(SetUtils.equals(test1, test2), is(false));
    }
    @Test
    public void test3() {
        Set<String> test1 = new HashSet<>();
        test1.add("a");
        test1.add("b");
        test1.add("c");
        Set<String> test2 = new HashSet<>();
        test2.add("a");
        test2.add("b");
        assertThat(SetUtils.equals(test1, test2), is(false));
    }
    //set ignore sequence
    @Test
    public void test4() {
        Set<String> test1 = new HashSet<>();
        test1.add("a");
        test1.add("b");
        Set<String> test2 = new HashSet<>();
        test2.add("b");
        test2.add("a");
        assertThat(SetUtils.equals(test1, test2), is(true));
    }
    @Test
    public void test5() {
        Set<String> test1 = new HashSet<>();
        test1.add("a");
        Set<String> test2 = new HashSet<>();
        test2.add("a");
        assertThat(SetUtils.equals(test1, test2), is(true));
    }
}

reproduced from: http://ju.outofmemory.cn/entry/288737